0
我是新来的pthreads在PHP中。我已经了解到,不可能从apache通过web服务器启动它,所以我已经使用laravel命令从命令行运行它,但是当我调用 start() 线程方法无法从Laravel命令启动线程
时,出现此错误PHP Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in [no active file]:0
Stack trace:
#0 {main}
thrown in [no active file] on line 0
但是,只要我调用run方法,错误就会消失,这是不行的。
我真的很感谢任何帮助,我可以得到。
我的命令的处理方法进行这样
public function handle()
{
$threads = ["Thread One", "Thread Two"];
$threadList=[];
foreach ($threads as &$thread){
//$id++;
$this->info($thread);
$testThread = new TestThread($thread);
$testThread->start();
$threadList[] = $testThread;
}
foreach ($threadList as $thread){
$this->info("waiting for thread ". $thread->getThreadID());
$thread->join();
$this->info($thread->getThreadID()."done ");
//echo $thread->getThreadID().'<br/>';
}
}
和我ThreadClass是这个
namespace App\Engine\Threads\ThreadClass;
use Illuminate\Support\Facades\Log;
class TestThread extends \Thread
{
private $threadID;
public function __construct($threadID)
{
$this->threadID = $threadID;
}
/**
* @return mixed
*/
public function getThreadID()
{
return $this->threadID;
}
public function run()
{
$this->threadID = $this->threadID.''.mt_rand(4000, 5000);
}
}
这让我倒了两天,谢谢。 –