Skip to content

Instantly share code, notes, and snippets.

@axgle
Created November 26, 2009 04:51
Show Gist options
  • Save axgle/243245 to your computer and use it in GitHub Desktop.
Save axgle/243245 to your computer and use it in GitHub Desktop.
class MTDaemon{
var $threads = 4;
var $idlesleeptime = 3;
var $run=true;
var $slot=0;
function __construct($threads = null, $idlesleeptime = null){
if ($threads) {
$this->threads=$threads;
}
if ($idlesleeptime) {
$this->idlesleeptime=$idlesleeptime;
}
}
function handle(){
while($this->run){
if ($this->slot>=$this->threads) {
pcntl_wait(&$status);
$this->slot--;
}
$next=$this->getNext($this->slot);
if ($next==null) {
continue;
}
if ($this->run==false) {
break;
}
if(pcntl_fork()==0){
$this->run($next,$this->slot);
exit;
}
$this->slot++;
}
}
function run($next,$slot){
}
function getNext($slot){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment