Crontab Linux run PHP script at a frequency of less than 1 minute

2

Please run the crontab to run every 1 second, you should run a .php script on the Debian Linux server.

          • root / usr / bin / php5 -q /var/www/cloudns.php

When running manual, it performs on a good, plus adding to there in crontab it does not run every 1 minute.

Kindly, if anyone can help me, it would help me a lot and I am grateful now! A hug.

    
asked by anonymous 15.03.2017 / 03:20

3 answers

1

The granularity of the cron is of 60 seconds, therefore, by "normal" routes it is not possible to accomplish what it wants, every 1 second.

One solution is to get around PHP itself.

An idea, which is even adopted by several frameworks such as Laravel, for example is, invoke cron every 1 minute (this time is variable, user defined).

cron would run the PHP script every minute.

Within the PHP script, an "infinite loop" is controlled with 1 second pauses.

So you'll get what you want.

If you want you can extend it, making cron run every 5 minutes. In this scheme the PHP script would run for 300 seconds, that is 300 iterations.

Of course, it is recommended that you have a second PHP script that will do the iterations in the background.

    
15.03.2017 / 06:14
0

First thing is that crontab runs the minimum period of 1 in 1 minute . So I'll explain how you do in that period Crontab does not run with username. It is not recommended to use root for crontab but if you still want to give the command:

sudo crontab -e

So you will create / edit a crontab table for the root user. Then add this line to the editor and put this:

*/1 * * * * /usr/bin/php5 -q /var/www/cloudns.php
    
15.03.2017 / 03:47
0

To run a script every second, you can combine the while while playing process background, for example:

while -n1 " /usr/bin/php5 -q /var/www/cloudns.php" &

Then the process will run every second until you kill it with kill , or reboot the machine.

    
21.03.2017 / 02:09