跳至 [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

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)