Heim  >  Artikel  >  Backend-Entwicklung  >  PHP Daemon开发-使用QPM管理PID文件

PHP Daemon开发-使用QPM管理PID文件

WBOY
WBOYOriginal
2016-08-08 09:29:161103Durchsuche
编写Daemon程序时,我们可以使用一个PID文件标记进程是否已经被创建,防止进程被重复启动,PID文件同时记录了进程号,以便于向进程发送信号。QPM中的pidfile正是用来管理PID文件的模块。例子:#pid_main.php start(); while(true) sleep(10); ?> 首次执行 php pid_main.php,我们能看到生成了 pid_main.php.pid文件,进程持续运行。 再次执行 php pid_main.php,脚本报错,提示进程已经存在。 Fatal error: Uncaught exception 'qpm\pidfile\Exception' with message 'process exists, no need to start a new one' in .../qpm/pidfile/Manager.php:41此外,qpm\pid\Manager 还有getProcess 方法。#pid_check.php getProcess()->getPid(); ?> 如果pid文件不存在或为空,则会抛出异常。 注意:getProcess方法获取的对象,并不100%确保是原进程。后续版本会改进这里的检测。

以上就介绍了PHP Daemon开发-使用QPM管理PID文件,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn