Answer the question
In order to leave comments, you need to log in
Maintain the number of running copies of a PHP script?
Hello.
There is a message queue on memcacheQ. It is necessary to maintain the number of PHP scripts that listens to it at a certain level, so that at any given time there will be at least N pieces. Writing your own demon that will do this (high-quality) is not a hunt, besides, once I saw in the comments on the hub a link to a software that someone made for the same purposes before me.
Help me find it please
Answer the question
In order to leave comments, you need to log in
The problem is solved by supervisord.org/ . the solution is stable and working.
Gearman
queue server ?
habrahabr.ru/post/123451/
habrahabr.ru/post/142210/
I would use pcntl functions. In short, the code looks like this (just to clarify the idea)
<?php
runDaemon(10);
function runDaemon( $aMaxWorkers )
{
$i = 0;
for ( ; $i < $aMaxWorkers; $i++ )
{
forkWorker( $i );
}
while ( ( $pid = pcntl_wait( $status ) ) != -1 )
{
echo "Exit $pid\n";
forkWorker( $i++ );
}
}
function forkWorker( $aNumber )
{
$pid = pcntl_fork();
if ( $pid )
{
echo "Start #$aNumber, pid $pid\n";
return;
}
// Делаем свою работу и выходим
sleep(5);
exit;
}
?>
while(count($this->currentJobs)){
echo "Waiting for current jobs to finish... \n";
sleep(1);
}
A bike:
#!/bin/bash
N=5
while : ; do
n=$(pgrep -flc "php ...")
while $n -le $N; do
logger "Run $n/$N"
php ...
: $[n++]
done
sleep 60
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question