Set up a cronjob for FreshRSS automatic update

FreshRSS does not import news automatically, but only when we open the portal. How to solve the problem.

Not all that glitters is gold, a phrase that also goes perfectly with FreshRSS as, as comfortable and pleasant as it may be, it has one major flaw: the failure to automatically update the feeds. In fact, being a self-hosted product for servers with apache, until someone accesses the service, it does not start the synchronization of the news.

All this leads to a probable loss of news especially with regard to feeds that have a very high news flow, because if a news site publishes on average 200 or more news per day, and we only access FreshRSS in the evening, this will synchronize the flow only for the latest items received, as a rss feed communicates a very limited number of updates. This blog, for example, in the rss feed only communicates the last 10 articles, but updates occur once a day so those who follow it do not risk losing anything.If, on the other hand, the Corriere publishes 200 news items a day, its rss feed will contain (by eye) only the last 100 items, and by accessing the service only once a day we risk losing at least half of the news published.

This problem can be solved by setting up a self-updating procedure which, run several times a day, guarantees the population of the news database by all the sources we follow even when we are not using the service.

Configure FreshRSS auto update

Inside the FreshRSS installation, precisely in the app/ folder, we find the actualize_script.php file that takes care of carrying out the news update process. It would be enough to simply run it with a cronjob, but the problem is that this script can only be executed with a command launched from the shell. In order to configure a cronjob we must therefore create a bridge that executes the shell command, and which we will then recall with a cronjob. We will therefore assume that your site is on a linux server.

The first thing we need to do is get the address of our domain inside the server that hosts us, and to do this we just need to create a php file in any position with this instruction inside

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

if for example, by loading the get_root.php file with that instruction within our domain, we just need to access it from the browser at www.domain.ext/get_root.php to receive the position that our site has within the server (dedicated or shared). Assuming a result like /home/mhd/www.domain.ext/htdocs, we have identified the htdocs folder of our site.

To be even clearer, if the freshrss installation location is www.domain.ext/freshrss, the folder location on the server is /home/mhd/www.domain.ext/htdocs/freshrss.

Having clarified this very important step, after deleting the get_root.php file we created, we will create a new file, calling it as we want, of type php, let’s paste this instruction

<?php

ini_set('max_execution_time', 600);

ini_set('max_execution_time', 600);


$command = "php /home/mhd/www.domain.ext/htdocs/freshrss/app/actualize_script.php";

echo shell_exec($command); // will return the output to a variable


?>

making sure to paste into the $command variable, including the php command, the exact location of the actualize_script.php file of the server hosting our site. At this point, let’s save the file in the FreshRSS root. Again for the usual clarity, if we called the file auto_update.php, we will have to put it at the position www.domain.ext/freshrss/auto_update.php.

We’re almost done.

At this point we need to create a cronjob, and to do that we can use any service, Cron-Job.org is fine too. Let’s create what is a new job, and insert in the url to be called our www.domain.ext/freshrss/auto_update.php, and let’s run it every 15 minutes.

What will happen at this point? – That CronJob will execute the auto_update.php script that we have configured, and that inside it contains the execution of a shell command that calls the actualize_script.php file that updates all the feeds. In this way our database will be populated every 15 minutes eliminating the problem of the loss of contents even if we access the service.

We periodically check the functioning of the links in our articles. If you notice any links that do not work, please let us know in the comments. If you enjoyed the article consider supporting the blog with a small donation. Thank you. Patreon / Ko-fi / Liberapay / Paypal

Leave a Reply

Your email address will not be published. Required fields are marked *