Killing a node process after .exec() in php on mac OS
I have the following code on a PHP page, which executes a node command for me.
<?php
if (isset($_POST['button'])) { exec('/usr/local/bin/node DroneNotes/Dronestream/server.js'); } ?>
<form method="POST">
<p>
<input type="hidden" name="button" value="1">
<input type="submit" value="Start Video">
</p>
</form>
The command is executing fine for me but the process is just hanging and not stopping for me. Im wondering could I kill the process in some way by creating another button click or can something be added in to end it after a certain time?
I don't think that it is a good idea to start a server for each client... if you have 100 clients in same time, you will start 100 times your server.js ? did you think about using differents port ?
To respond to your question: you have to create a script shell, that it starts your server, and it can killing it after period of time.
There are a good examples here to do your job Bash script that kills a child process after a given timeout
Check out this question to exit Node.js at the end of the process;
How to exit in Node.js
Or you can use "forever" to start and stop a node.js server manually;
forever start DroneNotes/Dronestream/server.js
forever stop DroneNotes/Dronestream/server.js
链接地址: http://www.djcxy.com/p/52716.html
上一篇: 如何退出JavaScript中的回调循环