开发者

Run shell commands with PHP?

Occasionally my media server goes down and I'm wondering if it's possible to start it remotely using php to check the port and if it's not running invoke cron (or some other way) to run a shell command. Is this possible because this is not a strong area for me. Here's the process I use with PuTTy.

  1. login to shell
  2. cd to source/red5/dist
  3. screen
  4. ./red5.sh
  5. CTRL-A then D to detach
  6. log开发者_开发问答out


Simplest thing is to write a shell script. And then login to remote console via PHP.

  • shell_exec: execute a shell command and returns the output as string.
  • exec: just executes an external program


A simple way to achieve what you want is to run this in screen:

while /bin/true ; do ./red5.sh ; done


If you can write a shell script that does what you need, then PHP's has exec(), system() and passthru() for you.


PHP actually has a special operator for executing shell commands, the backtick:

`cd source/red5/dist`

will go to the specified directory. (But I don't know much about shell, so I can't implement you the whole thing.)

If you need much control over the execution (I don't know whether you need here) use proc_open.


you can use corn job on php and put all command on .sh file and run like this

59 11 * * 1,2,3,4,5 root command file.sh?token

something like this ,it will be save


There is more than one good answer here, but you should opt for executing the init script for red5 instead of the .sh or .bat. There are pre-made init scripts here: http://code.google.com/p/bigbluebutton/downloads/detail?name=red5&can=2&q= and here: http://www.videowhisper.com/forum.php?ftid=48&t=init-file-red5-linux-installations-red5-linux-init.d-chkconfig

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜