Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP pcntl script - need guidance
    primarykey
    data
    text
    <p>I am working on a scraping project, somewhere in the application I need this functionality </p> <p>run a script again and again with a pause of some seconds.</p> <p>I tried to use pcntl to accomplish the job. so wrote this script</p> <pre><code>/************************/ $intra_sleep=10; // we're going to set the intra process launch sleep at 10 seconds $task_process=null; // by default this is set to null -- do nothing $loop_limit=0; // this is the number of times the loop shoul run -- if set to -1 look infinite number of times if (isset($argv[1])) $task_process=$argv[1]; if (isset($argv[2])) $intra_sleep=$argv[2]; if (isset($argv[3])) $loop_limit=$argv[3]; for ($loop_count=0; $loop_limit==-1 ? true : $loop_count&lt; $loop_limit; $loop_count++) { $pid= pcntl_fork(); if ($pid == -1) { die('MASTER: could not fork'); } else if ($pid==0) { if ($task_process) { echo "Sleeping for $intra_sleep Seconds\n"; sleep($intra_sleep); echo "Launching Child \n\n"; exec($task_process); // from here process script is being launched } else { echo " CLONE: no task process defined -- doing nothing " . PHP_EOL; } } else { pcntl_waitpid($pid,$status); } } /*********************/ </code></pre> <p>I am calling this script from CLI like this way</p> <pre><code>nohup php /this/script.php "php /path/to/process.php" 10 -1 </code></pre> <p>I expect that process.php will be launched again and again with 10 seconds intervals. It was doing work what I was expecting, but when I check runing processes, there were thousands processed running, launched by this script.</p> <p>My requirement is very simple: a script should be launched again and again with 10 second Pause.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload