跳至 [1] [全屏预览]
pidfile = __DIR__ . '/' . self::PIDNAME . '.pid'; } /** * @return int */ private function daemon() { if (file_exists($this->pidfile)) { echo "The file $this->pidfile exists.\n"; exit(); } $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { // we are the parent exit($pid); } else { // we are the child file_put_contents($this->pidfile, getmypid()); posix_setuid(self::uid); posix_setgid(self::gid); cli_set_process_title(self::PROCESS_NAME); pcntl_signal(SIGHUP, [$this, 'signoH']); pcntl_signal(SIGTERM, [$this, 'signoH']); pcntl_signal(SIGCHLD, [$this, 'signoH']); pcntl_signal(SIGQUIT, [$this, 'signoH']); pcntl_signal(SIGINT, [$this, 'signoH']); pcntl_signal(SIGUSR1, [$this, 'signoH']); return (getmypid()); } } /** * */ private function run() { do { pcntl_signal_dispatch(); if ($this->stop) { break; } echo "I am alive" . mt_rand(0,20) . "...\n"; sleep(5); } while (true); echo ("进程退出\n"); } public function restart() { $this->stop(); $this->start(); print "重启成功!\n"; } /** * */ private function start() { $pid = $this->daemon(); $this->run(); } /** * */ private function stop() { if (file_exists($this->pidfile)) { $pid = file_get_contents($this->pidfile); posix_kill($pid, SIGKILL); unlink($this->pidfile); } } /** * @param $proc */ private function help($proc) { printf("%s start | stop | restart | stat | help \n", $proc); } /** * @param $argv */ public function main($argv) { if (count($argv) < 2) { printf("please input help parameter\n"); exit(); } if ($argv[1] === 'stop') { $this->stop(); } else if ($argv[1] === 'start') { $this->start(); } else if ($argv[1] === 'restart') { $this->restart(); } else if ($argv[1] === 'stat') { if (is_file($this->pidfile)) { posix_kill(file_get_contents($this->pidfile), SIGHUP); } else { print "\n_______程序没有启动________\n"; } } else { $this->help("command list :"); } } /** * @param $instance * @param $channelName * @param $message */ public function handle($instance, $channelName, $message) { file_put_contents(__DIR__ . "/$channelName.txt", $message . "\n", FILE_APPEND); } /** * @param $signo */ public function signoH($signo) { switch ($signo) { case SIGHUP : print "\n___________运行状态___________\n"; print "HOST :" . self::HOST . "\n"; print "PORT :" . self::PORT . "\n"; print "NAME : " . self::PROCESS_NAME . "\n"; print "PID : " . file_get_contents($this->pidfile) . "\n"; print "________________________________\n"; break; case SIGTERM: posix_kill(file_get_contents($this->pidfile), 9); break; default : print "\n________________________________\n"; print "呀!~有人想杀掉我!\n"; print "________________________________\n"; } } }
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前ByDDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前ByDDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前ByDDD
<🎜>:死铁路 - 如何完成所有挑战
4 周前ByDDD
Atomfall指南:项目位置,任务指南和技巧
1 个月前ByDDD

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

禅工作室 13.0.1
功能强大的PHP集成开发环境