laravel-async-queue
                                
                                 laravel-async-queue copied to clipboard
                                
                                    laravel-async-queue copied to clipboard
                            
                            
                            
                        Job executed synchronously when app running in PHP executable
I created an async job for a long processing tasks, it gets correctly executed asynchronously when the app is running via apache mod_php, but it gets executed synchronously when the app is running via the PHP CLI server mode.
same problem here, any solution? if we Queue::push its awaiting..
im on windows btw.. solution:
public function startProcess($jobId, $delay = 0)
{
    chdir($this->container['path.base']);
    pclose(popen($this->getCommand($jobId, $delay), "r"));
    //exec($this->getCommand($jobId, $delay));
}
Tks @nmkr, now is running smoothly
PHP cli is blocking, can only have 1 request. Not sure if that is the problem. But cli mode is only for testing right?
And is this Linux? Or Windows? I'll try to reproduce and try the popen way.
@barryvdh For me it's on linux. PHP cli is blocking but that should not be the issue, since the async queue spawns a new process, no ? And, yes the cli is mostly used in dev mode I assume as well.
I have the same problem, but also when the app is running via apache mod_php... By replacing exec with popen and pclose, it works (I'm on windows).
Okay will check it out. Perhaps bring the Symfony process component back.
In the user contributed notes of exec in php.net (http://php.net/manual/fr/function.exec.php), there is this comment, if it can help:
This will execute $cmd in the background (no cmd window) without PHP waiting for it to finish, on both Windows and Unix.
<?php
function execInBackground($cmd) {
    if (substr(php_uname(), 0, 7) == "Windows"){
        pclose(popen("start /B ". $cmd, "r")); 
    }
    else {
        exec($cmd . " > /dev/null &");  
    }
}
?>
So it seems that popen and pclose must be used on windows for execution in background.
Can you all try this, using the Symfony Process command?
public function startProcess($jobId, $delay = 0)
{
    $command = $this->getCommand($jobId, $delay);
    $cwd = $this->container['path.base'];
    $process = new \Symfony\Component\Process\Process($command, $cwd);
    $process->run();
}
@barryvdh Works fine for me :)
Okay cool, if the rest can confirm (can also try 0.3.x@dev) I'll push a new tag.
For me it's still synchronous (PHP 5.6.5 CLI, linux).
I've tried with $process->start(); instead of $process->run(); (as per http://symfony.com/doc/current/components/process.html#running-processes-asynchronously) but still no success.
What's odd is that it seems to be sync only for PHP commands. If I replace the command with $process = new \Symfony\Component\Process\Process("sleep(10)", $cwd); it's async as expected.
Strange. How I did it before is also how Laravel does it: https://github.com/laravel/framework/blob/388aa6a1c3aa16a4e7f6fa850fa6f08bd3143ccd/src/Illuminate/Console/Scheduling/Event.php#L126