/** * Parses command line arguments * @param Daemon $d */ public static function parseArgs(Daemon $d) { global $argc, $argv; if (php_sapi_name() != 'cli') { return; } if ($argc == 2) { switch ($argv[1]) { case 'start': $d->start(); break; case 'stop': $d->stop(); break; case 'restart': $d->restart(); break; case 'status': $status = $d->status(); echo static::getDaemonName($d) . " is" . ($status ? " " : " not ") . "running\n"; break; default: echo "Unknown command " . $argv[1] . "\n"; exit(2); } exit; } else { echo sprintf("usage: %s start|stop|restart|status", $argv[0]); exit(2); } }
}); $client->on("receive", function (swoole_client $cli, $data) use($pid) { lg("[{$pid}] Received: {$data}", __LINE__); $cli->close(); }); $client->on("error", function (swoole_client $cli) use($pid) { $cli->close(); //lg("[$pid] error then conn close", __LINE__); exit(0); }); $client->on("close", function (swoole_client $cli) use($pid) { //lg("[$pid] conn close", __LINE__); }); $client->connect('127.0.0.1', 8001, 0.5); //lg("[$pid] create conn succ", __LINE__); exit(0); } if (isset($argv[1])) { $daemon = new Daemon(['func' => 'send', 'fork_num' => 1]); switch ($argv[1]) { case 'r': $daemon->run(); break; case 'k': $daemon->stop(); break; case 's': $daemon->status(); break; } }