I am using Laravel 5.1 and I am trying to start several threads within a Command class:
$documents->chunk(1000, function($documentChunk) use (&$threads, &$threadNumber, &$repository) {
$threads[$threadNumber] = new MyThread($documentChunk);
$threads[$threadNumber]->start();
$this->info("Thread [".$threadNumber."] running");
$threadNumber++;
});
The $documents variable has been previously filled with some data retrieved from the database
In the MyThread class this is what I have:
<?php namespace App\Helpers;
use Download;
class MyThreadextends \Thread {
protected $chunk;
public function __construct($chunk) {
$this->chunk = $chunk;
}
public function run() {
...
$downloads = Download::select(...);
...
}
}
On the select line, I get a:
PHP Fatal error: Class 'Download' not found
However, if I call directly $threads[$threadNumber]->run() instead of $threads[$threadNumber]->start(), I do not have this error. Maybe it is a problem of class loading but I can't figure out what's the real problem and if it can be solved...
If someone could help me with this, I would be really grateful since it's been hours I'm on this problem.
Thanks, Killian.