我用pthread开发了一个cli线程,但是我有一个问题:
我的代码如下:
class workerThread extends Thread {
private $time;
public function __construct($i) {
$this->i = $i;
$this->time = time();
}
public function run() {
echo "Begin running...\n";
while (true) {
echo "[{$this->getThreadId()} : {$this->i}] ";
if ($this->time + 10 < time()) {
break;
}
usleep(1000000);
}
}
}
class AppTest_Controller_Main extends Core_Controller {
public function thread3Action() {
error_reporting(E_ALL);
echo "Start\n";
$worker = new workerThread(1024);
$worker->start();
}
}
运行cli命令on centos 6.5,php v5.5.33 zts with ptheads extension
php cli.php -r“AppTest / Main / thread3”
结果
分段错误
但是我在MVC之外的文件上运行测试线程然后它工作 这段代码在windows中工作。
请帮助我,谢天谢地!