public function actionTest() { SysLog::info(__METHOD__, __CLASS__); $response = $this->argv['response']; $res = (yield $this->test()); SysLog::debug(__METHOD__ . " res == " . print_r($res, true), __CLASS__); $response->end(" test response 16" . print_r($res, true)); (yield Swoole\Coroutine\SysCall::end('test for syscall end')); }
public static function loop() { \SysLog::info(__METHOD__, __CLASS__); /* 遍历自己的数组,发现时间超过预定时间段,且该IO的状态依然是未回包状态,则走超时逻辑 */ foreach (self::$event as $socket => $e) { $now = microtime(true); \SysLog::debug(__METHOD__ . " key == {$socket} now == {$now} timeout == " . $e['timeout'], __CLASS__); if ($now > $e['timeout']) { self::del($socket); $cli = $e['cli']; $cli->close(); call_user_func_array($e['callback'], $e['params']); } } }
public static function loop() { \SysLog::info(__METHOD__, __CLASS__); /* 遍历自己的数组,发现时间超过预定时间段,且该IO的状态依然是未回包状态,则走超时逻辑 */ foreach (self::$event as $socket => $e) { \SysLog::debug(__METHOD__ . " key == {$socket} ", __CLASS__); $res = time() - $e['timeout'] - self::LOOPTIME; if ($res >= 0) { self::del($socket); $cli = $e['cli']; $cli->close(); call_user_func_array($e['callback'], $e['params']); } } }
/** * [parseHeader description] * @param [type] $headerBuf [description] * @return [type] [description] */ private function parseHeader($data) { /* version + status_code + message */ $parts = explode("\r\n\r\n", $data, 2); $headParts = explode("\r\n", $parts[0]); if (is_string($headParts)) { $headParts = explode("\r\n", $headParts); } if (!is_array($headParts) || !count($headParts)) { //TODO header buffer valid return false; } list($this->rspHeaders['protocol'], $this->rspHeaders['status'], $this->rspHeaders['msg']) = explode(' ', $headParts[0], 3); unset($headParts[0]); foreach ($headParts as $header) { $header = trim($header); if (empty($header)) { continue; } $h = explode(':', $header, 2); $key = trim($h[0]); $value = trim($h[1]); $this->rspHeaders[strtolower($key)] = $value; } if (isset($parts[1])) { $this->buffer = $parts[1]; } \SysLog::debug(__METHOD__ . " header == " . print_r($this->rspHeaders, true), __CLASS__); return true; }