Created
November 26, 2009 04:51
-
-
Save axgle/243245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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