0

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?

Matthew
  • 1
  • 6

2 Answers2

1

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

Community
  • 1
  • 1
Halayem Anis
  • 7,233
  • 2
  • 18
  • 39
0

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
Community
  • 1
  • 1
cdagli
  • 1,530
  • 14
  • 22
  • I think the forever stop might work for me best in this situation. Could I add this in as a new button on the webpage and it would stop the server for me ? – Matthew Feb 15 '15 at 15:03
  • Yes, I believe you can exec it like you do in your sample code but please consider the answer below if that is the right way to do it. I don't know what you are trying to do but if you click that submit button twice unless you change the port you will get a ENOENT error because port can only be used with one server process. – cdagli Feb 15 '15 at 15:04