2016-06-24 18 views
1

私はサイトを掻き集めてデータを取得していますので、私はグーグルで仕事をしているので、キューがこのプロセスに適していることを発見しました'Closure'のシリアライズは許可されていませんlaravel Queue

Serialization of 'Closure' is not allowed 

マイコード:

class SiteScraper extends Job implements ShouldQueue 
{ 
    use InteractsWithQueue, SerializesModels; 

    protected $client; 
    protected $crawler; 

    /** 
    * Create a new job instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 

     $this->client = new Client(); 
     $this->crawler = $this->client->request('GET', 'example.com/login/'); 
     $form = $this->crawler->selectButton('Log In')->form(); 
     $this->crawler = $this->client->submit($form, array('email' => 'useremail', 'pass' => 'pass')); 
     $this->crawler->filter('.flash-error')->each(function ($node) { 
      print $node->text() . "\n"; 
     }); 
    } 
public function handle() 
{ 

    $crawler = $this->client->request('GET', $url_to_traverse); 
    $status_code = $this->client->getResponse()->getStatus(); 

     if($status_code == 200){ 
      $crawler->filter('.friendBrowserNameTitle > a')->each(function ($node) { 
       $names = $node->text() . '<br>'; 
       $profileurl = $node->attr('href') . '<br>'; 
       echo "Name : " . $names . " Profile Link : " . $profileurl; 

      }); 
     } 
     else{ 
      echo $status_code; 
     } 

    } 
} 

すべてのヘルプ私が間違っているんですか?

答えて

3

ジョブが(Source

を処理しているときにのみ雄弁モデルはだから私はあなたのケースでは、あなたが(ハンドルにあなたの現在の構造のコードを記述する必要があることを推測優雅にシリアル化され、シリアライズされます)方法

class SiteScraper extends Job implements ShouldQueue 
{ 
    use InteractsWithQueue, SerializesModels; 

    /** 
    * Create a new job instance. 
    * 
    * @return void 
    */ 
    public function __construct(){ } 

    public function handle() 
    { 

     $client = new Client(); 
     $crawler = $client->request('GET', 'example.com/login/'); 
     $form = $crawler->selectButton('Log In')->form(); 
     $crawler = $client->submit($form, array('email' => 'useremail', 'pass' => 'pass')); 
     $crawler->filter('.flash-error')->each(function ($node) { 
      print $node->text() . "\n"; 
     }); 

     $crawler = $client->request('GET', $url_to_traverse); 
     $status_code = $client->getResponse()->getStatus(); 

     if($status_code == 200){ 
      $crawler->filter('.friendBrowserNameTitle > a')->each(function ($node) { 
       $names = $node->text() . '<br>'; 
       $profileurl = $node->attr('href') . '<br>'; 
       echo "Name : " . $names . " Profile Link : " . $profileurl; 

      }); 
     } 
     else{ 
      echo $status_code; 
     } 

    } 
}