public function actionLog() { //for ($i = 0; $i < 1000; $i++) { YcfCore::$log->log('hello ycf' . time(), 'info'); YcfCore::$log->log('hello 123' . time(), 'info'); YcfCore::$log->log('hello 123' . time(), 'info'); YcfCore::$log->log('hello 123' . time(), 'info'); YcfCore::end("Greet, Klcoze!"); //} }
public function __construct() { date_default_timezone_set('Asia/Shanghai'); define('DEBUG', true); define('SWOOLE', true); define('DS', DIRECTORY_SEPARATOR); define('ROOT_PATH', realpath(dirname(__FILE__)) . DS . ".." . DS . ".." . DS); $this->http = new \swoole_http_server("0.0.0.0", 9501); $this->http->set(array('worker_num' => 2, 'daemonize' => true, 'max_request' => 1, 'task_worker_num' => 1, 'log_file' => ROOT_PATH . 'src/runtime/swoole.log')); $this->http->on('WorkerStart', array($this, 'onWorkerStart')); $this->http->on('WorkerStop', array($this, 'onWorkerStop')); $this->http->on('Start', array($this, 'onStart')); $this->http->on('request', function ($request, $response) { define('YCF_BEGIN_TIME', microtime(true)); //捕获异常 register_shutdown_function(array($this, 'handleFatal')); //请求过滤 if ('/favicon.ico' == $request->server['path_info'] || '/favicon.ico' == $request->server['request_uri']) { return $response->end(); } if (isset($request->server)) { self::$server = $request->server; foreach ($request->server as $key => $value) { $_SERVER[strtoupper($key)] = $value; } } if (isset($request->header)) { self::$header = $request->header; } if (isset($request->get)) { self::$get = $request->get; foreach ($request->get as $key => $value) { $_GET[$key] = $value; } } if (isset($request->post)) { self::$post = $request->post; foreach ($request->post as $key => $value) { $_POST[$key] = $value; } } if (isset($request->request_uri)) { $_SERVER['REQUEST_URI'] = $request->request_uri; } //$GLOBALS['httpServer'] = $this->http; ob_start(); //实例化ycf对象 try { $ycf = new YcfCore(); YcfCore::$response = $response; YcfCore::$httpServer = $this->http; $ycf->init(); $ycf->run(); } catch (Exception $e) { var_dump($e); } $result = ob_get_contents(); ob_end_clean(); YcfCore::end($result); unset($result); }); $this->http->on('Task', array($this, 'onTask')); $this->http->on('Finish', array($this, 'onFinish')); $this->http->start(); }