Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 29th, 2012  |  syntax: None  |  size: 1.06 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP pcntl script - need guidence
  2. /************************/
  3. $intra_sleep=10; // we're going to set the intra process launch sleep at 10 seconds
  4. $task_process=null; // by default this is set to null -- do nothing
  5. $loop_limit=0; // this is the number of times the loop shoul run -- if set to -1 look infinite number of times
  6.  
  7. if (isset($argv[1])) $task_process=$argv[1];
  8. if (isset($argv[2])) $intra_sleep=$argv[2];
  9. if (isset($argv[3])) $loop_limit=$argv[3];
  10.  
  11.  
  12. for ($loop_count=0; $loop_limit==-1 ? true : $loop_count< $loop_limit; $loop_count++)
  13. {
  14.   $pid= pcntl_fork();
  15.  
  16.    if ($pid == -1)
  17.    {
  18.     die('MASTER: could not fork');
  19.    }
  20.    else if ($pid==0)
  21.    {
  22.      if ($task_process)
  23.      {
  24.        echo "Sleeping for  $intra_sleep Secondsn";
  25.        sleep($intra_sleep);
  26.        echo "Launching Child nn";
  27.        exec($task_process); // from here process script is being launched
  28.      }
  29.      else
  30.      {
  31.     echo "  CLONE: no task process defined -- doing nothing " . PHP_EOL;
  32.      }
  33.   }
  34.   else
  35.   {
  36.      pcntl_waitpid($pid,$status);  
  37.   }
  38.  
  39.  
  40. }
  41.  
  42. /*********************/