Php Pthread-线程不运行?
我的问题很简单 第一类,它扩展了Php Pthread-线程不运行?,php,multithreading,laravel-4,Php,Multithreading,Laravel 4,我的问题很简单 第一类,它扩展了线程类: class FileSender extends Thread { private $client; public function __construct() { // it goes here, since it's called in the main thread } private function write($buff) { File::append(public_path
线程
类:
class FileSender extends Thread {
private $client;
public function __construct() {
// it goes here, since it's called in the main thread
}
private function write($buff) {
File::append(public_path()."/test.log", $buff.PHP_EOL);
}
public function run() {
$this->write("test");
while (true) {
$avatar = Pool::getNextAvatar();
if ($avatar !== null) {
$this->write("Preparing to send...");
// bla, bla, bla...
} else {
$this->write("No file to send");
sleep(60);
}
}
}
}
打电话的人:
$fs = new FileSender();
$fs->start();
while (true) {
sleep(10);
}
public/test.log
中的文件未填充。
你们知道为什么吗
如果我调用run()
它就可以正常工作,但我希望它是完全异步的
编辑
事实上,它将进入run()
函数,但只会持续几分钟。写入一个文件是相当繁重的事情,我认为当写入结束时,线程已经被终止(?)。但问题是为什么