Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "X-PPM-Restart" Header where the application can force a restart … #438

Closed
wants to merge 2 commits into from
Closed

Add "X-PPM-Restart" Header where the application can force a restart … #438

wants to merge 2 commits into from

Conversation

shyim
Copy link

@shyim shyim commented Nov 1, 2018

Like described in #437 i need something to restart programmatically a worker or all.

With this addition a Application can send in response header "X-PPM-Restart: worker" to restart the current worker which handled the response or "X-PPM-Restart: all" to restart all workers.

Why we need that? If a application has dynamic proxies and they change in the runtime, the application could send this header to restart the worker to load the new proxy.

I used strpos to find the header, if someone else have a better performant idea to read a header :)

@marcj
Copy link
Member

marcj commented Nov 1, 2018

I actually like the idea with the header 👍, but we need to make sure the http client on the other end doesn't receive that header.

@shyim
Copy link
Author

shyim commented Nov 1, 2018

Yes you are right :). I am looking where that should happends 🙈

@shyim
Copy link
Author

shyim commented Nov 1, 2018

To replace the Header i had to remove the piping and had done it in the data listener.
I have never used before React Stream, so i have no idea if this has performance issues... 🙈

@dnna
Copy link
Contributor

dnna commented Nov 3, 2018

Love the idea with the header :) Not sure either if the piping change has a performance impact though...

PS. Can we document this ability to restart somehow (maybe in the readme or somewhere else)? Would be a shame to forget about it and have to dig the code to find it again later.

@acasademont
Copy link
Contributor

mmm this involves manually mangling with the plain text http response, smells a bit fishy. Right now we don't allow custom ReactPHP middlewares but if we did and someone used the GzipMiddleware the plain text wouldn't be there anymore, just a stream of bytes.

I think this should go on the Slave level, before the bytes are piped to the master and when the headers are readable in the handleRequest function of the SlaveProcess class. The slave would either kill himself or signal the master to kill all slaves.

@marcj
Copy link
Member

marcj commented Nov 9, 2018

@acasademont Gzip only compresses the body, not the headers. So, we as the master should always receive the headers.

@acasademont
Copy link
Contributor

You're right! I'm too used to HTTP/2 :p At some point React will probably implement http2 too and then my point would be valid reactphp/http#99

Still feels like the master should only be a dispatcher and shouldn't mess around with what the Slaves work on.

@marcj
Copy link
Member

marcj commented Nov 9, 2018

Ah I see :) We have already a IPC pipe from all slaves to master (where we send for example all registered php files, see

protected function sendCurrentFiles()
), so we could use that again.

Would be something along the lines of:

Slave:

public sendRestartSignal() {
           $this->sendMessage($this->controller, 'restartSlave', ['mode' => 'all']);
           $this->sendMessage($this->controller, 'restartSlave', ['mode' => 'one', 'port' => $this->config['port']]);
}

Master:


protected function commandRestartSlave(array $data, ConnectionInterface $conn)
{
     if ('all' === $data['mode']) {
       //do stuff
    }
}

@andig
Copy link
Contributor

andig commented Mar 10, 2019

Hi all, not sure which direction this PR is currently heading in- are we waiting for further updates or ha this become obsolete?

@andig
Copy link
Contributor

andig commented Mar 20, 2019

Closing due to inactivity. Please respond here if you want to reopen this.

@andig andig closed this Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants