PHP多进程异常终止


   
  public function start(){
  

echo "Multi-process start\n";
while (true){
$this->parentRun();
echo "当前任务数:" . self::$isfork . "\n";

if(!$this->isFork()){
echo "wait " . $this->waitTime . "s\n";
sleep($this->waitTime);
continue;
}

echo date("Y-m-d h:m:s");
if ( $this->childCount <= $this->max ){

$deploy = array_pop(self::$queue);
$pid=pcntl_fork();
}else{

usleep(10000);
continue;
}
if ($pid == -1) {
die("could not fork");
} else if ($pid) {// we are the parent
echo 'childNum:'.$pid.', maxNum:'.$this->max."\n";
$this->childCount++;
$this->forkMinus();
echo 'childSum:' . $this->childCount."\n";
} else {// we are the child
$this->run($deploy);
exit();
}
}
}

以下代码会异常终止。不知都是什么原因

多线程 php

8158432 11 years, 5 months ago

我看你使用pcntl_fork函数来起子进程,但是这个pcntl_fork函数貌似只在Linux/Unix下会起作用。是不是你用在了Windows环境下?或者未进行编译。sorry,尝试答一次可能不正确。

ティッシュ姫 answered 11 years, 5 months ago

Your Answer