A
A
Alex Lav2019-07-30 20:15:28
PHP
Alex Lav, 2019-07-30 20:15:28

How to reduce the load on the site from PHP code when parsing RSS news feeds?

I have PHP code installed on my site

header("Content-Type: text/html; charset=utf-8");
$url = "https://vkrss.com/lJOxFYPHLRiItCUE/[xfvalue_vk]?filter=all"; // Адрес до RSS-ленты
$rss = simplexml_load_file($url);
foreach ($rss->channel->item as $items) {
echo <<<HTML
<h5><font color="white"><code>{$items->pubDate}</code></font></h5>
<p><font color="white">{$items->description}</font></p>
<a href="{$items->link}"><button class="label label-success" style="text-decoration: none;">
<font color="white"> Подробнее</font> 
</center>
</button>
</a>
<hr>
HTML;
}

After being installed on the page, it takes longer to load and sometimes the code does not work at all, or it does not work correctly. How can you reduce page load?
Maybe not output directly from the rss feed to the page, but write to a file on the host and parse from there? May I help?
Throw ideas from personal experience, many thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2019-07-30
@aleks78888

1. Fence news - once every N-minutes. It is possible by request, it is possible through cron.
2. After we took it, we cache it in a file ("raw" cache).
3. Then - we process it as it is necessary for output on the site and also save it to a file ("prepared" cache).
4. Output - always from the prepared cache file (to reduce the load on the hosting).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question