/** * array( * pid: 进程id * time: 运行时间 * sleep:休眠时间 * ) */ function yze_daemon_status() { $pid = yze_getpid(); if (!$pid) { return array(); } $f = popen("ps -eo pid,tty,user,comm,etime | grep '{$pid} .* php'", "r"); $string = fgets($f); pclose($f); if (!$string) { return array(); } $cliinfo = preg_match_all("/[^\\s]+/", trim($string), $matchs); $sleep = function_exists("yze_get_sleep") ? yze_get_sleep() : 60; return array('pid' => $pid, "time" => trim(@$matchs[0][4]), "sleep" => $sleep); }
<?php /** * 启动进程的脚本 */ include 'cli.php'; $pid = yze_getpid(); if ($pid) { exec("kill -9 {$pid}"); clear_pid(); } yze_run_daemon();