2

Hy! Can you make multithreadding in Laravel 5.2 by default? I'm currently using Jobs and Queues, but queue:listen or queue:work run only one job at time. I need a method that is made in code, not like Supervisor. So run the cron, and if there are 4 jobs waiting, run them async. As I mentioned in title, I also agree multi process, but I have no idea how it work. I've tried to put those commands in a loop, but still take just one job at time.

public function handle()
{

    $jobsWaiting = Job::where('jobstatus', 'w')->where('jobtype', 'send')->where('approved', 1)->get();

    foreach ($jobsWaiting as $job) {
        $this->dispatch(new SendEmail($job->id));
    }

    $x = 1;
    while ($x <= count($jobsWaiting)) {
        exec("php artisan queue:work --daemon");
        $x++;
    }
} 

This is the method that runs at cron, but not work :(

EBuzila
  • 211
  • 2
  • 4
  • 16
  • What about [threads](http://php.net/manual/en/book.pthreads.php)? – apokryfos Jun 08 '16 at 14:29
  • It's about my boss, don't want that. it's a little bit complicated, as I have to recompile php etc.. – EBuzila Jun 08 '16 at 14:41
  • Since you already have `exec` in place you could try the solution at http://stackoverflow.com/questions/3139177/how-can-i-run-a-program-in-the-background-non-blocking-with-php – apokryfos Jun 08 '16 at 14:42
  • I guess I need this https://alfrednutile.info/posts/106, but no idea how to put that on Laravel 5.2 – EBuzila Jun 08 '16 at 14:43
  • That one seems to be using [Symphony's Proccess Component](http://symfony.com/doc/current/components/process.html) – apokryfos Jun 08 '16 at 14:47
  • I've tried with '> /dev/null 2>/dev/null &' but i says that the command does not exists. where should i put it? is like 'exec("php artisan queue:work > /dev/null 2>/dev/null &")'? – EBuzila Jun 08 '16 at 14:58

0 Answers0