rialto-php / rialto

Manage Node resources with PHP
MIT License
170 stars 80 forks source link

Node process is not properly killed #10

Closed shawoozy closed 6 years ago

shawoozy commented 6 years ago

It should be possible to fetch the PID of the process running by rialto.. I think there is a method for it but it is not accessible.

nesk commented 6 years ago

While writing the initial basecode of Rialto, I've added a method to get the process PID but removed it later because the library should be smart enough to manage its own Node process.

Rialto's goal is to provide a complete abstraction over the PHP/Node communication, providing a method to get the process PID would ruin this abstraction because the process could be killed (or whatever else) by the developer.

However, before rejecting the idea, maybe could you tell me why you need the PID? What will you do with it? If it's only for debugging purposes, you can already get the PID through a logger. 😉

shawoozy commented 6 years ago

Thank you for responding. My php application launches a node process and I need to have the possibility to kill the node process without killing php. Maybe I'm doing something wrong but sometimes the node process keeps living.

nesk commented 6 years ago

Then we should consider this as a bug. I will need some informations to help you:

If you have some additional context, please provide it.

shawoozy commented 6 years ago

Before we are sure its a bug and I deliver what you asked, is there a way to stop a process ? I do not think it should be complicated. I think I'm doing something wrong. I'm using your puppeteer wrapper and when I want to stop the process im doing the following.

$this->browser->close();

 unset($this->page);

 unset($this->browser);

  unset($this->puppeteer); 
nesk commented 6 years ago

The Node process is automatically killed when all the resources are unset (manually or not). For example:

$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();

$page = $browser->newPage();
$page->goto('https://example.com');

$browser->close();

Here we have multiple resources created:

Since all these resources aren't used anymore at the end of the script, PHP's garbage collector will destroy the instances. When the last resource is destroyed, the underlying ProcessSupervisor instance (common to all the resources) will be destroyed too and the Node process will be killed.

FIY: $browser->close() is mandatory here, the browser will be automatically closed once the Node process is killed.

Your PHP script, is it part of a long-running process? If it's the case, please check if you're not keeping a reference to a resource somewhere (in global variable, in a parent class, etc…).

However, this is strange because the Node process should kill itself after a while without receiving any instructions (and this is tested). Maybe your OS is preventing this?

nesk commented 6 years ago

@sharokh1 Anything new?

shawoozy commented 6 years ago

Hi, sorry for not replying earlier! When the resources are unset, the puppeteer (node) process continuous to run in the background. To fix this, we made sure the php process is killed. This way all the relevant processes will also be killed.

nesk commented 6 years ago

So, should I consider this issue as fixed?

If you want, you can provide me with a code reproducing the bug, and I can try by myself to see what’s the cause of this.

nesk commented 6 years ago

Closing since the issue is inactive.