$return = fread(self::$fp, 4096); $response->end($return); return true; } else { $response->end(json_encode(call_user_func_array(array(new Manager(), $rte[1] . "_http"), array("request" => $request)))); return true; } } } } return false; } public static function run($fd) { self::$fp = fopen("php://fd/" . $fd, "a"); swoole_set_process_name(self::$name); self::http_server(); self::start(); } } if (!empty($argv[2])) { Http::$conf_file = $argv[2]; } if (!empty($argv[3])) { Http::$host = $argv[3]; } if (!empty($argv[4])) { Http::$port = $argv[4]; } Http::run($argv[1]);
<?php /** * @author jan huang <*****@*****.**> * @copyright 2016 * * @link https://www.github.com/janhuang * @link http://www.fast-d.cn/ */ include __DIR__ . '/../vendor/autoload.php'; class Http extends \FastD\Swoole\Server\Http { /** * @param \FastD\Http\SwooleServerRequest $request * @return \FastD\Http\Response */ public function doRequest(\FastD\Http\SwooleServerRequest $request) { switch ($request->server->getPathInfo()) { case '/session/set': $request->session->set('user', ['name' => 'jan', 'age' => 19]); return $this->html('ok'); case '/session/get': return $this->json($request->session->toArray()); default: return $this->html('hello swoole http server'); } } } Http::run('http://0.0.0.0:9527', SWOOLE_PROCESS, ['debug' => true]);
<?php include __DIR__ . '/../vendor/autoload.php'; class Http extends \FastD\Swoole\Server\Http { /** * @param \FastD\Http\SwooleServerRequest $request * @return mixed */ public function doRequest(\FastD\Http\SwooleServerRequest $request) { $request->cookie->set('name', 'jan'); return new \FastD\Http\JsonResponse(['msg' => 'hello world'], 400, ['NAME' => "Jan"]); } } Http::run('http://0.0.0.0:9527');