2016-06-24 18 views
1

Ich kratze eine Website ein paar Daten und es ist eine Zeit, Job zu nehmen, so dass ich gegoogled und festgestellt, dass Queue für diesen Prozess gut ist Ich bin in diesem Fehler steckenSerialisierung von 'Closure' ist nicht erlaubt laravel Queue

Serialization of 'Closure' is not allowed 

Mein Code:

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; 
     } 

    } 
} 

Jede Hilfe, wo ich falsch gehe?

Antwort

3

Nur Eloquent Modelle werden anmutig serialisiert und deserialisiert werden, wenn der Auftrag verarbeitet wird (Source)

Damit ich denke, in Ihrem Fall, müssen Sie Ihr aktuelles Konstrukt Code in Griff schreiben() Methode

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; 
     } 

    } 
}