#!/usr/bin/env php <?php define('zoop_dir', dirname(__FILE__) . '/../../framework'); define('app_dir', dirname(__FILE__)); include zoop_dir . '/Zoop.php'; Zoop::loadLib('Pherver'); $chatserver = new HttpServer(); $chatserver->run('127.0.0.1', 9050);
$response->header('Content-Type', 'application/vnd.collection+json'); // logic layer $res_arr = static::hotLogic($request, $this->json_col, $this->getRedisIns()); if (array_key_exists('code', $res_arr)) { $code = $res_arr['code']; $response->status($code); echo 'StCode:' . $code . PHP_EOL; if (201 == $code) { //created extra header $response->header('Location', Json_Collection::$host . '/' . $res_arr['location']); } } else { // 200 is the default code $this->json_col->fillWithArr($res_arr['arr']); $ret_str = $this->json_col->getEncodedStr(); $this->json_col->cleanUp(); } $httpcontent = isset($ret_str) ? $ret_str : ''; unset($ret_str); echo 'Ret_Cont:' . $httpcontent . PHP_EOL; $response->end($httpcontent); } public function run() { $this->serv->start(); } } $http = new HttpServer(); $http->setting(); $http->run();
$log = "{$message} ({$file}:{$line})\nStack trace:\n"; $trace = debug_backtrace(); foreach ($trace as $i => $t) { if (!isset($t['file'])) { $t['file'] = 'unknown'; } if (!isset($t['line'])) { $t['line'] = 0; } if (!isset($t['function'])) { $t['function'] = 'unknown'; } $log .= "#{$i} {$t['file']}({$t['line']}): "; if (isset($t['object']) && is_object($t['object'])) { $log .= get_class($t['object']) . '->'; } $log .= "{$t['function']}()\n"; } if (isset($_SERVER['REQUEST_URI'])) { $log .= '[QUERY] ' . $_SERVER['REQUEST_URI']; } error_log($log); $this->response($this->currentFd, $log); } } $server = new HttpServer(); $server->onRequest(function ($server) { $server->response("<h1>hello world</h1>"); }); $server->run();