2014-01-30 58 views
1

Bellow是我用來驗證電子郵件地址存在的腳本,使用pthreads來提高速度。 問題是,當我把它放在Laravel命令我得到這個錯誤:使用pthreads時Laravel命令出錯

Fatal error: Call to undefined method Illuminate\Support\Facades\Log::error() in /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 208 

這是腳本:

<?php 

      use Illuminate\Console\Command; 
      use Symfony\Component\Console\Input\InputOption; 
      use Symfony\Component\Console\Input\InputArgument; 



      class verifyLocal extends Command 
      { 

       protected $name = 'verify:local'; 
       protected $description = 'verify emails from local server'; 



       public function __construct() 
       { 
        parent::__construct(); 

       } 

       public function fire() 
       { 
        $start = microtime(true); 
        $emails = array(
         new WebRequest("[email protected]"), 
         new WebRequest("[email protected]") 
        ); 

        $threads = array(); 

        foreach ($emails as $k => $email) { 
         $req[$k] = new WebRequest($email); 
         $threads[$k] = new WebWorker(); 
         $threads[$k]->start(); 
         $threads[$k]->stack($req[$k]); 
        } 

        /* wait for completion */ 
        foreach ($threads as $thread) { 
         $thread->shutdown(); 
        } 

        foreach ($req as $r) { 
         var_dump($r); 
        } 

        $time = microtime(true) - $start; 
        printf("Fetched %d responses in %.3f seconds\n", count($req), $time); 

       } 

      } 




      class WebRequest extends Stackable { 
       public $email_address; 
       public $response_body; 

       public function __construct($email_address) { 
        $this->email_address = $email_address; 
       } 

       public function run(){ 
        $this->response_body = $this->check($this->email_address); 
       } 

       public function check($email) { 
        /* verification code here */ 
        $answer = true; 
        return $answer; 
       } 


      } 

      class WebWorker extends Worker { 
       public function __construct() { 

       } 
       public function run(){ 

       } 
      } 


      ?> 

任何幫助,請。謝謝。

回答

2

我不使用Laravel,我的猜測是,你需要安裝磁帶自動加載機在工體/線程的run方法,使laravel將正常工作,嘗試第一...

foreach ($emails as $k => $email) { 
    $req[$k] = new WebRequest($email); 
    $threads[$k] = new WebWorker(); 
    $threads[$k]->start(); 
    $threads[$k]->stack($req[$k]); 
} 

這說明你想爲每封電子郵件創建一個工作者,這確實是非常浪費的。

+0

謝謝。我會試試這個。 – kpios