diff --git a/node.php b/node.php
index 84f2ebc..8ebf14d 100644
--- a/node.php
+++ b/node.php
@@ -12,6 +12,9 @@
define("ADMIN_MODE", false); //set to true to allow unsafe operations, set back to false when finished
+//set to true for shared hosts that periodically kill user's processes (such as node)
+define("RESTART_PROCESS", false);
+
define("NODE_VER", "v5.7.0");
define("NODE_ARCH", "x" . substr(php_uname("m"), -2)); //x86 or x64
@@ -72,6 +75,9 @@ function node_start($file) {
$node_pid = exec("PORT=" . NODE_PORT . " " . NODE_DIR . "/bin/node $file >nodeout 2>&1 & echo $!");
echo $node_pid > 0 ? "Done. PID=$node_pid\n" : "Failed.\n";
file_put_contents("nodepid", $node_pid, LOCK_EX);
+ if($node_pid>0){
+ file_put_contents('nodestart', $file, LOCK_EX);
+ }
sleep(1); //Wait for node to spin up
echo file_get_contents("nodeout");
}
@@ -118,6 +124,17 @@ function node_serve($path = "") {
echo "Node.js is not yet running. Switch to Admin Mode and Start it\n";
node_foot();
return;
+ }elseif($RESTART_PROCESS && $node_pid && !posix_getpgid($node_pid)){
+ $nodestart = file_get_contents('nodestart');
+ if($nodestart){
+ node_start($nodestart);
+ //wait for node process to start, then retry to node_serve
+ sleep(5);
+ node_serve($path);
+ return;
+ }
+ echo "Please switch to Admin Mode and manually restart the server. Start it\n";
+ return;
}
$curl = curl_init("http://127.0.0.1:" . NODE_PORT . "/$path");
curl_setopt($curl, CURLOPT_HEADER, 1);