niutech / node.php

Run node.js apps from PHP even on a shared hosting!
813 stars 236 forks source link

Added a restart for hosting that kills user processes #14

Open Sustenance opened 8 years ago

Sustenance commented 8 years ago

Some shared hosting, such as Namecheap, will periodically kill off users' processes. This should allow the process to be restarted when a request comes in while the process is dead.

Sustenance commented 8 years ago

Actually, don't merge this yet. I need to add a check that the node PID is still alive - just realized that it wasn't actively checking that on each serve

niutech commented 8 years ago

Thank you for your contribution. Could you please add spaces around { }? And I am not sure if checking for $node_pid in the if statement is necessary. Finally, is there a need to run node_serve recursively, instead of just continuing to curl_init?

Sustenance commented 8 years ago

I can make the requested changes. I called node_serve recursively so that it would redo the check for the PID. Unfortunately, between yesterday and today, my hosting provider seems to be killing this node process immediately, so this is causing a race condition. Have you seen that at all, where node is started successfully via node.php, but an immedate ps -e doesn't show the PID? Manually starting node via SSH works fine

niutech commented 8 years ago

No, I haven't experienced it. Does $! also return nothing?

Sustenance commented 8 years ago

Sorry I let this PR die. The host I was using (NameCheap) has an autokiller on its shared hosting apparently, and kills node as soon as it starts. Doesn't look like I'll be able to continue contributing.