function execute(Mpass_Request $client) { try { $header = ''; $header = $client->read(1024); $request = new RequestModel($header); $handle = HandleFactory::getResponseHandle($request->isStatic()); $response = $handle->handle($header); $client->write($response); Mpass_Log::record($header, __METHOD__); return true; } catch (Exception $e) { $EResponse = 'HTTP/1.0 ' . $e->getCode() . ' ' . $e->getMessage() . chr(13) . chr(10); $EResponse .= 'Date:' . date("D, d M Y G:i:s \\G\\M\\T") . chr(13) . chr(10) . chr(13) . chr(10); $client->write($EResponse); Mpass_Log::record($EResponse, __METHOD__); return true; } }
public function run($client) { $request = new Mpass_Request($client); if (FALSE === $request->initialized) { Mpass_Log::err("initialized request failed, client \"" . stream_socket_get_name($client) . "\"", __METHOD__); return FALSE; } /* set timeout */ set_time_limit(30); /* ignore all quit signal */ $signals = array(SIGINT => "SIGINT", SIGHUP => "SIGHUP", SIGQUIT => "SIGQUIT"); foreach ($signals as $signal => $name) { pcntl_signal($signal, SIG_IGN); } $ret = $this->_executor->execute($request); if (version_compare(phpversion(), "5.2.1", "ge")) { stream_socket_shutdown($client, STREAM_SHUT_RDWR); } else { fclose($client); } unset($request); return TRUE; }
public static function err($str, $scope = "") { self::$last_error = $str; self::record($str, "ERROR", $scope); }
protected function _cleanup() { if (!$this->is_master) { return; } Mpass_Log::log("cleanup", __METHOD__); $this->_running = FALSE; while ($this->_children > 0) { $pid = pcntl_wait($status, WNOHANG | WUNTRACED); if ($pid > 0) { if (FALSE === pcntl_wifexited($status)) { Mpass_Log::warn("sub proccess {$pid} exited unormally with code {$status}", __METHOD__); } else { Mpass_Log::log("sub proccess {$pid} exited normally", __METHOD__); } $this->_children--; } else { continue; } } if ($this->_socket) { if (version_compare(phpversion(), "5.2.1", "ge")) { stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR); } else { fclose($client); } } }