trigger node js file
Assuming you're on Unix-based OS:
You can run shell commands via the exec() function:
// in php file// to start the script exec("node myscript.js &", $output);
$output
becomes an array of each line of output, so you can see what the process id is. Then you would use that process id to kill the script:
exec("kill " . $processid);
I would avoid any direct interaction with the shell. It would probably be the safest, to solve it this way:
- implement some overall "service"-script, that launches the user-node-app and keeps it running (something like https://github.com/isaacs/node-supervisor)
- Make it, so it automatically reboots on changes of either the relevant files or a database-entry
- With the user triggering a reboot, add a flag (timestamp?) to the database-entry or file that is watched by the reboot-script. It then will reboot the node.js-app/script.