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

Asked

Viewed 2,214 times

2

Please, I need to run crontab so that it runs every 1 second, you should run a . php script on the Debian Linux server.

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

when executing manual, it performs a good, plus adding ai to crontab it does not run every 1 minute.

Please, if someone could help me, it would help me a lot and I am grateful from now on! A hug.

  • 1

    Explain why you want to run this script once a second... just out of curiosity. Sometimes there is a better solution q put q vc want to do in a php program (interpreted) in crontab.

3 answers

1

Cron granularity is 60 seconds, therefore, by "normal" ways it is not possible to accomplish what you want, every 1 second.

One solution is to bypass with 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 you control an "infinite loop" with 1-second breaks.

So you get what you want.

If you want you can prolong, making the cron run every 5 minutes. In this scheme the PHP script would be running for 300 seconds, ie 300 iterations.

Of course for this it is recommended that you have a second PHP script which is what will make the iterations in the background.

0

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

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

And then the process will run every second until you kill him with the kill, or restart the machine.

0

First thing is that crontab executes the minimum period of 1 in 1 minute.So I’ll explain to you how you do in this period crontab does not run under the user name. It is not recommended to use root share 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 in the editor and put this:

*/1 * * * * /usr/bin/php5 -q /var/www/cloudns.php
  • making tests.... I saw something on the command internet: Sleep time_em_seconds && , check?

  • Check it out. I can’t imagine a business running second to second. One option is to run the script when it starts, and within the script you make an infinite loop...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.