Advertisement
cloudtuts

PHP background procress

Jan 6th, 2021 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2. // https://github.com/cocur/background-process
  3. use Cocur\BackgroundProcess\BackgroundProcess;
  4.  
  5. require dirname(__DIR__).'/vendor/autoload.php';
  6.  
  7. if(!isset($_SERVER['WTSERVER'])||$_SERVER['WTSERVER']!='windows'){
  8.     ini_set('log_errors', 'On');
  9.     ini_set('display_errors', 'Off');
  10.     ini_set('error_log', dirname(__FILE__).'/error_log.log');
  11. }
  12.  
  13. $process=new BackgroundProcess();
  14. $process->run();
  15.  
  16. error_log(print_r(sprintf('Crunching numbers in process %d', $process->getPid()), true));
  17.  
  18. $intValue=1;
  19. while($process->isRunning()){
  20.     error_log($intValue);
  21.     sleep(1);
  22.     $intValue++;
  23.     if($intValue>=1000){
  24.         $process->stop();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement