1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <?php
$http = new swoole_http_server("127.0.0.1", 9501); $http->set( [ 'worker_num' => 2, 'dispatch_mode' => 1, ] ); $http->on('request', function ($request, $response) { App::init($request, $response); $result = (new A())->run(); $response->end("子进程(" . getmypid() . ")完成请求的处理:" . $result); }); $http->start(); echo "主进程(" . getmypid() . ")已启动";
class App {
public static $GPC;
public static function init($request, $response) { foreach (['get', 'post', 'cookie', 'files'] as $attr) { self::$GPC[$attr] = property_exists($request, $attr) ? $request->$attr : []; } $response->header("Content-Type", "text/html; charset=UTF-8"); } }
class A { public function run() { return var_export(App::$GPC, true); } }
|