Method of Timing Task Execution Based on PHP

  • 2021-07-21 08:04:39
  • OfStack

This paper describes the example of PHP to implement the method of executing tasks regularly, and the code is simple and practical. Share it for your reference.

The specific implementation method is as follows:


ignore_user_abort(true); // Ignore script abort when client disconnects (allow script 1 Direct execution) 
set_time_limit(0);  // Set the maximum script execution time, 0 Unlimited 
do{
  $handle = fopen('auto.txt', 'w');
  if($fp)
  {
    $text = ' How do you do \n\r';
    $count = 0;
    for($i=1; $i<10; $i++)
    {
      if(! $c = fwrite($handle, ' No. 1 '.$i.' Line: '.$text)) // Returns the number of characters written, or in case of failure false
      {
        echo ' No. 1 '.$i.' Write failed for the second time !';
      }
      $count += $c;
    }
  }
  fclose($handle);
  sleep(60); // Delay 60 Second execution 
}while(true);

I hope this article is helpful to everyone's PHP programming.


Related articles: