@@ -29,9 +29,9 @@ class WorkermanServer {
2929
3030 private $ options ;
3131
32- private $ events =[];
33-
3432 private $ wCount ;
33+
34+ public $ onWorkerStart ;
3535
3636 /**
3737 *
@@ -76,12 +76,6 @@ private function configure($http) {
7676 $ http ->set ($ this ->options );
7777 }
7878
79- private function addEvents ($ http ){
80- foreach ($ this ->events as $ event =>$ callback ) {
81- $ http ->on ($ event ,$ callback );
82- }
83- }
84-
8579 public function init ($ config , $ basedir ) {
8680 $ this ->config = $ config ;
8781 $ this ->basedir = $ basedir ;
@@ -112,35 +106,38 @@ public function run($host, $port, $options = []) {
112106 $ this ->setOptions ($ options );
113107 $ this ->server =new Worker ("http:// $ host: $ port " ,$ this ->options );
114108 $ this ->server ->count =$ this ->wCount ??4 ;
109+ if (isset ($ this ->onWorkerStart )){
110+ $ this ->server ->onWorkerStart =$ this ->onWorkerStart ;
111+ }
115112 $ this ->server ->onMessage =function ($ connection ,$ datas ){
116- $ this ->handle ($ connection ,$ datas );
113+ return $ this ->handle ($ connection ,$ datas );
117114 };
118115 Worker::runAll ();
119116 }
120117
121118
122119 protected function handle (ConnectionInterface $ connection ,$ datas ) {
123- $ _REQUEST ['REQUEST_TIME_FLOAT ' ]=\microtime (true );
124- Http::header ('Date: ' .gmdate ('D, d M Y H:i:s ' ).' GMT ' );
120+ // $_REQUEST['REQUEST_TIME_FLOAT']=\microtime(true);
121+ Http::header ('Date: ' .\ gmdate ('D, d M Y H:i:s ' ).' GMT ' );
125122 $ _GET ['c ' ] = '' ;
126123 $ uri = \ltrim (\urldecode (\parse_url ($ _SERVER ['REQUEST_URI ' ], PHP_URL_PATH )), '/ ' );
127124 if (($ uri == null || ! ($ fe =\file_exists ($ this ->basedir . '/../ ' . $ uri ))) && ($ uri !='favicon.ico ' )) {
128125 $ _GET ['c ' ] = $ uri ;
129126 } else {
130127 if ($ fe ){
131128 Http::header ('Content-Type: ' . HttpCache::$ header ['Accept ' ] ?? 'text/html; charset=utf-8 ' ,true );
132- $ connection ->send (\file_get_contents ($ this ->basedir . '/../ ' . $ uri ));
129+ return $ connection ->send (\file_get_contents ($ this ->basedir . '/../ ' . $ uri ));
133130 }else {
134131 Http::header ('Content-Type: ' . HttpCache::$ header ['Accept ' ] ?? 'text/html; charset=utf-8 ' ,true ,404 );
135- $ connection ->send ($ uri .' not found! ' );
132+ return $ connection ->send ($ uri .' not found! ' );
136133 }
137134 return ;
138135 }
139136
140137 $ this ->httpInstance ->setDatas ($ datas );
141138 \ob_start ();
142139 \Ubiquity \controllers \Startup::forward ($ _GET ['c ' ]);
143- $ connection ->send (\ob_get_clean ());
140+ return $ connection ->send (\ob_get_clean ());
144141 }
145142 /**
146143 * Sets the worker count
0 commit comments