0

I've just learned how to setup and start a web-socket server using Ratchet.

I've learned how to start the script using a command from the terminal and the script keeps running forever.

What I want to know now, is how can I start and stop that script (the web-socket server) using php code, not terminal, So that I can have a button to start and stop the web-socket server whenever I want ?

This question might seem naive, but I don't have a clue on how to this, I am new to Ratchet and web-socket.

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
michael
  • 1
  • 3

1 Answers1

-1

If you know the pid, then just use command,

exec("kill -9 $pid");

Otherwise, you can use

exec("pkill $progname"); //To kill a any command with name as $progname

Please refer to this for more such options.

How to kill all processes with a given partial name?

Umashankar Das
  • 601
  • 4
  • 12
  • what do you mean by **with name as $progname**, can you give an example? – michael May 28 '17 at 04:18
  • $progname defines the name of the program which you want to kill. For example if you want to kill terminals, use "pkill -f term" This will kill any program which has a pattern like term. If avoid -f then you have to give exact program name like say your script , "shellscript.sh" $progname will store the name "shellscript.sh" – Umashankar Das May 28 '17 at 04:21