amphp / process

An async process dispatcher for Amp.
MIT License
229 stars 32 forks source link

'Could not start process' (0) #26

Closed staabm closed 6 years ago

staabm commented 6 years ago

my process I try to start, errors while starting up.

I get errors like

Uncaught exception: 'Amp\Process\ProcessException' with message 'Could not start process' (0)
> in /cluster/www/www/www/rocket/vendor/amphp/process/lib/Internal/Posix/Runner.php:88
Stack trace:
#0 /cluster/www/www/www/rocket/vendor/amphp/process/lib/Process.php(96): Amp\Process\Internal\Posix\Runner->start('{ ('/usr/bin/ph...', '', Array, Array)
#1 /cluster/www/www/www/rocket/vendor/amphp/parallel/lib/Context/Process.php(166): Amp\Process\Process->start()
#2 /cluster/www/www/www/rocket/vendor/amphp/parallel/lib/Worker/AbstractWorker.php(59): Amp\Parallel\Context\Process->start()
#3 /cluster/www/www/www/rocket/vendor/amphp/parallel/lib/Worker/DefaultPool.php(137): Amp\Parallel\Worker\AbstractWorker->enqueue(Object(BlockingTask))
#4 /cluster/www/www/www/rocket/helpers/ImageHelper.php(73): Amp\Parallel\Worker\DefaultPool->enqueue(Object(BlockingTask))
#5 [internal function]: {closure}('a', NULL)
#6 /cluster/www/www/www/rocket/vendor/amphp/amp/lib/Coroutine.php(39): Generator->current()
#7 /cluster/www/www/www/rocket/vendor/amphp/amp/lib/Loop/Driver.php(119): Amp\Coroutine->__construct(Object(Generator))
#8 /cluster/www/www/www/rocket/vendor/amphp/amp/lib/Loop/Driver.php(70): Amp\Loop\Driver->tick()
#9 /cluster/www/www/www/rocket/vendor/amphp/amp/lib/Loop.php(76): Amp\Loop\Driver->run()
#10 /cluster/www/www/www/rocket/helpers/ImageHelper.php(80): Amp\Loop::run(Object(Closure))

I guess the problem itself is, that proc_open is on the disable_functions list and therefore php does not allow to start the process.

my calling code looks like

function resize_image($filename, $destinations = null, $allowEnlarge = false)
{
    $result = true;

    Amp\Loop::run(function () use ($filename, $destinations, $allowEnlarge, &$result) {
        $pool = new DefaultPool();

        $promises = array();
        foreach($destinations as $name => $params) {
            $promises[] = $pool->enqueue(new BlockingTask('resize_image_process', $filename, array($name => $params), $allowEnlarge));
        }

        foreach($promises as $promise) {
            $result = $result && yield $promise;
        }
        $result = $result && yield $pool->shutdown();
    });

    return $result;
}

while I am using classes from the examples from the parallel component https://github.com/amphp/parallel/tree/master/examples

staabm commented 6 years ago

just did some test, which confirmed that my problem is proc_open is on the disable_function list.

would be great to get a better error message in this case, so you dont need to dig into the dark.

kelunik commented 6 years ago

@staabm Do you want to provide a PR?

staabm commented 6 years ago

I will give it a try. Could take a few weeks though

staabm commented 6 years ago

tried to repro this behaviour on my windows laptop at home and could't repro with basic-command from within the process\examples repos.

C:\xampp7.1.4\htdocs\amphp\process>C:\xampp7.1.4\php\php.exe examples\basic-command.php
PHP Fatal error:  Uncaught Amp\Process\ProcessException: Could not start process Errno: 2; proc_open() has been disabled for security reasons in C:\xampp7.1.4\htdocs\amphp\process\lib\Internal\Windows\Runner.php:88
Stack trace:
#0 C:\xampp7.1.4\htdocs\amphp\process\lib\Process.php(96): Amp\Process\Internal\Windows\Runner->start('cmd /c echo Hel...', '', Array, Array)
#1 C:\xampp7.1.4\htdocs\amphp\process\examples\basic-command.php(14): Amp\Process\Process->start()
#2 [internal function]: {closure}('a', NULL)
#3 C:\xampp7.1.4\htdocs\amphp\process\vendor\amphp\amp\lib\Coroutine.php(39): Generator->current()
#4 C:\xampp7.1.4\htdocs\amphp\process\vendor\amphp\amp\lib\Loop\Driver.php(119): Amp\Coroutine->__construct(Object(Generator))
#5 C:\xampp7.1.4\htdocs\amphp\process\vendor\amphp\amp\lib\Loop\Driver.php(70): Amp\Loop\Driver->tick()
#6 C:\xampp7.1.4\htdocs\amphp\process\vendor\amphp\amp\lib\Loop.php(76): Amp\Loop\Driver->run()
#7 C:\xampp7.1.4\htdocs\amphp\process\examples\basic-command.php(20): Amp\Loop::run(Object(Closure))
# in C:\xampp7.1.4\htdocs\amphp\process\lib\Internal\Windows\Runner.php on line 88

so it seems the origin issue might be related to non-windows builds, or it is somehow related to the Abstraction classes used in the more complex example scripts posted above.

still investigating.

staabm commented 6 years ago

another idea: this is fixed behaviour in the current master version which is not yet published (or is not part) of the installed package of my at-office VM (can verify this only in a few weeks after PTO)

staabm commented 6 years ago

tried to repro the code from the initial description on windows with latest parallel/process and couldn't repro the error neither.

kelunik commented 6 years ago

Closing this issue then.