/** * 开启http服务 web api * @param $opt */ public static function params_http($opt) { if (!isset($opt["http"])) { return false; } if (isset($opt["host"]) && $opt["host"]) { self::$host = $opt["host"]; } if (isset($opt["port"]) && $opt["port"]) { self::$port = $opt["port"]; } $process = new swoole_process(array(new Main(), "http_run")); $process->start(); self::$http_server = $process; swoole_event_add($process->pipe, function ($pipe) use($process) { $manager = new Manager(); $recv = $process->read(); $recv = explode("#@#", $recv); $function = $recv[0] . "_cron"; $process->write(json_encode($manager->{$function}(json_decode($recv[1], true)))); }); return true; }
public static function start() { if (file_exists(self::$pid_file)) { die("Pid文件已存在!\n"); exit; } swoole_process::daemon(); $process = new swoole_process(array(new Main(), "http_run")); $process->start(); self::$http_server = $process; if (!function_exists("posix_getpid")) { Main::log_write("Please install posix extension." . "\n"); exit; } Main::log_write("dddd "); self::$pid = posix_getpid(); Main::log_write("pid " . self::$pid); file_put_contents(self::$pid_file, self::$pid); }