2016-09-27 190 views
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); 

    } 


} 

回答