Home php Does PHP have an analogue setTimeout, like JavaScript?

Does PHP have an analogue setTimeout, like JavaScript?




Actually question in the title. Task: Run the PHP script, but if all the conditions for its execution are not ready, then perform it again, after 10 seconds? Is there any kind of functionality in PHP?

Answer 1, Authority 100%

Here is an example, cycle limited three iterations ($ i & lt; 3 ), which is performed with a delay of 10 seconds Sleep (10) , if necessary, the number of iterations can be enlarged and / or add some condition instead of echo

& lt;? php
For ($ i = 0; $ i & lt; 3; $ i ++) {
  $ Date = New DateTime ();
  Echo "Iteration No. $ i, performed in." $ Date- & gt; Format ("H: M: S"). "& lt; br & gt;";
  SLEEP (10);

Answer 2

For similar purposes, you can use CRON.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions