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 | <?php $http = new swoole_http_server( '0.0.0.0' , 8080); $http ->set([ 'worker_num' => 8, 'enable_static_handler' => true, 'document_root' =>__DIR__ . '/../public/static' , ]); $http ->on( 'WorkerStart' , function (swoole_server $server , int $worker_id ){ //定义应用目录 // define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 require __DIR__ . '/../thinkphp/base.php' ; }); $http ->on( 'request' , function ( $request , $response ){ if (isset( $request ->server)){ foreach ( $request ->server as $k => $v ){ $_SERVER [ strtoupper ( $k )] = $v ; } } if (isset( $request ->header)){ foreach ( $request ->header as $k => $v ){ $_SERVER [ strtoupper ( $k )] = $v ; } } if (isset( $request ->get)){ foreach ( $request ->get as $k => $v ){ $_GET [ $k ] = $v ; } } if (isset( $request ->post)){ foreach ( $request ->post as $k => $v ){ $_POST [ $k ] = $v ; } } ob_start(); try { // 执行应用并响应 think\Container::get( 'app' )->run()->send(); } catch (\Exception $e ){ // todo } $res = ob_get_contents(); ob_end_clean(); print_r( $res ); $response -> end ( $res ); }); $http ->start(); |