PHP守护Linux/Unix进程
加上文件的可执行权限:
$ chmod +x /home/heiyeluren/php_daemon2.php
在服务器上执行命令:
$ nohup /home/heiyeluren/php_daemon2.php &
就进入了后台运行,我们通过Windows的客户端telnet上去:
C:\>telnet 192.168.0.1 10000
如果提示:
正在连接到192.168.0.188…不能打开到主机的连接, 在端口 10000: 连接失败
则说明服务器端没有开启,或者上面的程序没有正确执行,请检查php是否 –enable-sockets 功能。如果提示:
==========================================
Welcome to the PHP Test Server.
To quit, type ‘quit’.
To shut down the server type ‘shutdown’.
To get help message type ‘help’.
==========================================
php>
则说明顺利连接上了我们的PHP写的服务器端守护进程,在php>提示符后面能够执行help、quit、shutdown等三个命令,如果命令输入不是这三个,则提示:
php> asdf
PHP: unknow command ‘asdf’.
执行help命令可以获取帮助
php> help
PHP Server Help Message
To quit, type ‘quit’.
To shut down the server type ‘shutdown’.
To get help message type ‘help’.
这个服务器端就不介绍了,可以自行扩展。
杀进程跟例子一类似。
[ 总结 ]通过以上学习,我们知道php也可以做守护进程,如果设计的好,功能也会比较强大,不过我们这里只是学习而已,可以自行研究更新。
i really enjoyed your post.
….interesting….
Good grief!
Thankyou for all your inspiration and for the goodness you spread.
I have followed this one-year process through your editorials and articles. Thank you for your clear and reasonable position.
it is such a colorful description.
this will be amazing
your words are just food for the soul! Fantastic!