I have an http server on Linux.
I have some PHP code that refreshes my cache and I would like to execute this code every 500 milliseconds whenever the server is running, even after a server restart.
I was thinking of implementing a service but I don't have much experience with Linux so I don't know how to do this or if it is even the right approach.
I also heard of cron-jobs but I see that they run by the minutes and not by the seconds.
How can I execute PHP code in Linux every 500 milliseconds(Code would be helpful)?

- 2,848
- 4
- 31
- 51
-
3Check this: http://stackoverflow.com/questions/1726116/run-a-php-script-every-second-using-cli – Mirko Brombin Mar 31 '16 at 16:08
2 Answers
Yo can set a cron job for it. But cron job have some limitations, as per hosting. The minimum time interval you can set is one minute. But for your achievement you can set a loop in your file and run it for 1 minute. And again cron job will trigger this file, After one minute.

- 1,229
- 11
- 17
The truth is that crons can only be accurate to the seconds anyway. It is not intended for high frequency/precision executions, in fact it's very possible that a cron execution is off by a few seconds.
Keep in mind, something executing every 500 milliseconds is pretty frequent, just a heads up because it could be process intensive. If you really want to use cron though, about the best you can do is every minute. You can edit your crontab file by running this command:
crontab -e
And then in the file, add:
* * * * * /path/to/your/php/script.php
If you do this, then inside your php script (/path/to/your/php/script.php
), you can have php code that loops for a minute, and clears cache every 500 milliseconds.

- 1,549
- 1
- 11
- 16