Я новичок в pthreads в php. Я узнал, что это невозможно запустить из apache через веб-сервер, поэтому я прибегал к использованию команд laravel для запуска из командной строки, но я получаю эту ошибку, когда вызываю метод start() потокаНе удалось запустить Thread from Laravel Command
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);
}
}
Это меня заколотило пару дней, спасибо. –