Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Job executed synchronously when app running in PHP executable #30

Open
jvelo opened this issue Jan 20, 2015 · 15 comments
Open

Job executed synchronously when app running in PHP executable #30

jvelo opened this issue Jan 20, 2015 · 15 comments

Comments

@jvelo
Copy link

jvelo commented Jan 20, 2015

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.

@nmkr
Copy link

nmkr commented Jan 29, 2015

same problem here, any solution? if we Queue::push its awaiting..

@nmkr
Copy link

nmkr commented Jan 29, 2015

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

@grzmartins
Copy link

Tks @nmkr, now is running smoothly

@barryvdh
Copy link
Owner

PHP cli is blocking, can only have 1 request. Not sure if that is the problem. But cli mode is only for testing right?

@barryvdh
Copy link
Owner

And is this Linux? Or Windows? I'll try to reproduce and try the popen way.

@jvelo
Copy link
Author

jvelo commented Feb 15, 2015

@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.

@bioteck
Copy link

bioteck commented Feb 17, 2015

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).

@barryvdh
Copy link
Owner

Okay will check it out. Perhaps bring the Symfony process component back.

@bioteck
Copy link

bioteck commented Feb 17, 2015

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.

@barryvdh
Copy link
Owner

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 added a commit that referenced this issue Feb 18, 2015
barryvdh added a commit that referenced this issue Feb 18, 2015
@bioteck
Copy link

bioteck commented Feb 18, 2015

@barryvdh Works fine for me :)

@barryvdh
Copy link
Owner

Okay cool, if the rest can confirm (can also try 0.3.x@dev) I'll push a new tag.

@jvelo
Copy link
Author

jvelo commented Feb 18, 2015

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.

@jvelo
Copy link
Author

jvelo commented Feb 18, 2015

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.

@barryvdh
Copy link
Owner

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants