K
K
Kirill Gorelov2017-10-11 16:49:52
PHP
Kirill Gorelov, 2017-10-11 16:49:52

Execute php script every 10 seconds?

Guys, such a question.
You need to execute a php script every 10 seconds.
How can I do it?
I now have 3 options for solving this problem:
1. https://habrahabr.ru/post/132609/
2. according to the crown, but so that the script works during. And run the script once a minute.
3. Arrange a message queue, but I still don't know how to do it at all.
Please let me know which would be the best option. Or maybe you have another solution?
I have my own server, problems with the load and other things should not arise!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
davidnum95, 2017-10-11
@davidnum95

infinite loop + sleep?

R
RidgeA, 2017-10-11
@RidgeA

several types of crowns

* * * * * php myscript.php
* * * * * sleep 10 && php myscript.php
* * * * * sleep 20 && php myscript.php
* * * * * sleep 30 && php myscript.php
* * * * * sleep 40 && php myscript.php
* * * * * sleep 50 && php myscript.php

PS
1. The option with a constantly running php script is bad, IMHO. memory leaks can accumulate, it is much better for him to die.
2. We must not forget about flock to prevent the next cron from starting if the previous one has not yet worked, if this is important.

V
Vadim Milevsky, 2017-10-12
@3gsxarakiri

Make one cron, for every minute, and then add your status check to the script.
So at the first call, you will start the process and save the state somewhere. After that, if it takes a long time to run, the second request will first check your status, if it says that I'm still running, then it will complete the call, otherwise it will execute .
You can implement it yourself, I personally use the symphony package - LockHandler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question