Skip to content

Commit dafb1fa

Browse files
authored
Merge pull request #1 from phpMv/techempower-benchmarks
Techempower benchmarks
2 parents 25d4486 + 3ee6cc7 commit dafb1fa

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

composer.lock

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Ubiquity/servers/workerman/WorkermanServer.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Ubiquity/utils/http/foundation/WorkermanHttp.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ public function setResponseCode($responseCode) {
5656
if (PHP_SAPI != 'cli') {
5757
return \http_response_code($responseCode);
5858
}
59-
if (isset(HttpCache::$codes[$responseCode])) {
60-
HttpCache::$header['Http-Code'] = "HTTP/1.1 $responseCode " . HttpCache::$codes[$responseCode];
61-
return true;
62-
}
59+
Http::responseCode($responseCode);
60+
return $responseCode;
6361
}
6462
return false;
6563
}

0 commit comments

Comments
 (0)