0
私はPHPのpthreadsを初めて使用しています。私は、それがコマンドラインからそれを実行するためにlaravelコマンドを使用することに頼っていたので、Webサーバーを介してApacheから起動することができないことを学んだが、 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
しかし、実行方法を呼び出すときはいつでもエラーが消えてしまいますが、これは行く方法ではありません。
本当にありがとうございます。
私のコマンドのハンドル方法は、このように
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);
}
}
これは私に数日間困惑しました。ありがとうございました。 –