rialto-php / puphpeteer

A Puppeteer bridge for PHP, supporting the entire API.
MIT License
1.34k stars 208 forks source link

The process has been unexpectedly terminated. #114

Open balkoonline opened 4 years ago

balkoonline commented 4 years ago

Hi. I have installed nesk/puphpeteer according to instructions. It works on localhost but it throws errors when it is installed on hosting:

index.php `<?php

require 'vendor/autoload.php';

use Nesk\Puphpeteer\Puppeteer;

$puppeteer = new Puppeteer;`

Error log: `Fatal error: Uncaught Nesk\Rialto\Exceptions\ProcessUnexpectedlyTerminatedException: The process has been unexpectedly terminated. in /path/to/vendor/nesk/rialto/src/ProcessSupervisor.php:314 Stack trace:

0 /path/to/vendor/nesk/rialto/src/ProcessSupervisor.php(344): Nesk\Rialto\ProcessSupervisor->checkProcessStatus()

1 /path/to/vendor/nesk/rialto/src/ProcessSupervisor.php(149): Nesk\Rialto\ProcessSupervisor->serverPort()

2 /path/to/vendor/nesk/rialto/src/AbstractEntryPoint.php(30): Nesk\Rialto\ProcessSupervisor->__construct('/path/to...', Object(Nesk\Puphpeteer\PuppeteerProcessDelegate), Array)

3 /path/to/vendor/nesk/puphpeteer/src/Puppeteer.php(34): Nesk\Rialto\AbstractEntryPoint->__construct('/path/to... in /path/to/vendor/nesk/rialto/src/ProcessSupervisor.php on line 314`

What could be wrong? Thank you.

balkoonline commented 4 years ago

I have just found also that function serverPort() in /vendor/nesk/rialto/src/ProcessSupervisor.php on line 331 is not returning valid integer value, to be precise it is not returning any value as $iterator is ignored by foreach loop.

protected function serverPort(): int
    {
        if ($this->serverPort !== null) {
            return $this->serverPort;
        }

        $iterator = $this->process->getIterator(SymfonyProcess::ITER_SKIP_ERR | SymfonyProcess::ITER_KEEP_OUTPUT);

        foreach ($iterator as $data) {
            return $this->serverPort = (int) $data;
        }

        // If the iterator didn't execute properly, then the process must have failed, we must check to be sure.
        $this->checkProcessStatus();
    }

I hope this will help you to determine what could be a problem.

spekulatius commented 4 years ago

You can get code blocks highlighted using three ` @balkoonline. What PHP versions are you running locally and on production?

balkoonline commented 4 years ago

Thanks @spekulatius for useful tip :) ... About PHP versions:

7.4.11 on localhost - working 7.3.16 on web hosting production - not working

spekulatius commented 4 years ago

No worries @balkoonline.

While the error doesn't look like it's directly related I would keep at least the minor versions similar (e.g. 7.3. locally and on production). Are you able to adjust it either locally or production to have a common base to compare it to?

One question in this context: Do you run composer update as part your deployment? Otherwise you would push 7.4 packages onto an env with 7.3 runtime.

balkoonline commented 4 years ago

@spekulatius I have changed local version of PHP to 7.3.16 so it is the same as on the production server now. The same behavior... script works on localhost and doesn't work on production server. About the composer update... I have installed fresh packages on production with only composer.json and package.json files and executing update commands. Installation went through without errors.

composer update
npm update

composer. json contents:

{
  "require": {
    "nesk/puphpeteer": "^1.6"
  }
}

package.json contents:

{
  "dependencies": {
    "@nesk/puphpeteer": "^1.6.0"
  }
}
spekulatius commented 4 years ago

Okay, good - now you got a way investigating the issues better. Are you able to share your PHP script using PuPHPeteer or is index.php your whole script already? This would make debugging much easier.

balkoonline commented 4 years ago

@spekulatius the simplified index.php (3 lines) is everything what is executed. While debugging I found that function serverPort() is not returning a value on production server while it returns integer on localhost. To that point everything seems to work exactly the same on both localhost and production server.

spekulatius commented 4 years ago

There should be a port, that's for sure. Not entirely sure what the reason is, can you share your node version and operating system?

balkoonline commented 4 years ago

Versions:

Ubuntu 18.04.4 PHP 7.3.16 Node 12.16.3 Composer 1.10.6 NPM 6.14.5

spekulatius commented 4 years ago

Could you add a logger?

Here is explained how to do it: https://github.com/rialto-php/puphpeteer/blob/master/.github/contributing.md#provide-logs-with-your-bug-report

balkoonline commented 4 years ago

I have added logger and here is the output:

Fatal error: Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'node' '/path/to/vendor/nesk/puphpeteer/src/get-puppeteer-version.js'" failed. Exit Code: 127(Command not found) Working directory: /path/to/working/directory
Output:
================
Error Output:
================
in /path/to/vendor/symfony/process/Process.php:252
Stack trace:
#0 /path/to/vendor/nesk/puphpeteer/src/Puppeteer.php(62): Symfony\Component\Process\Process->mustRun()
#1 /path/to/vendor/nesk/puphpeteer/src/Puppeteer.php(42): Nesk\Puphpeteer\Puppeteer->currentPuppeteerVersion('node')
#2 /path/to/vendor/nesk/puphpeteer/src/Puppeteer.php(30): Nesk\Puphpete in /path/to/vendor/symfony/process/Process.php on line 252

It is strange that node command is not found as node -v works in SSH. I have to contact my hosting provider. Thank you for assistance @spekulatius ;)

spekulatius commented 4 years ago

Happy to help, just not sure I can resolve your issue. Have you tried to cd into the folder and run the command 'node' '/path/to/vendor/nesk/puphpeteer/src/get-puppeteer-version.js' manually? Does this result in the same failure?

MrBLT commented 3 years ago

I had this same issue and have been debugging for the past 3 days. In my case it was working on dev through a symfony local web server, but was failing on live which is an IIS Web server.

My problem turned out to be that the user tied to the Application Pool for the IIS website did not have permissions to perform these actions, so I set the user to someone who did and it we're up and running again! I found the solution here https://stackoverflow.com/questions/11575386/foo-cmd-wont-output-lines-in-process-on-website