Skip to content

Commit 2af7405

Browse files
committed
update handle method add parseURI
1 parent 45b1183 commit 2af7405

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"workerman"
1212
],
1313
"require" : {
14-
"php" : ">7.0",
14+
"php" : ">=7.4",
1515
"workerman/workerman": "~3.5"
1616
},
1717
"license" : "Apache-2.0",

src/Ubiquity/servers/workerman/WorkermanServer.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class WorkermanServer {
3434

3535
public $onWorkerStart;
3636

37+
private static $uriInfos;
38+
3739
/**
3840
*
3941
* @return int
@@ -120,11 +122,12 @@ protected function handle(ConnectionInterface $connection, $datas) {
120122
// $_REQUEST['REQUEST_TIME_FLOAT']=\microtime(true);
121123
Http::header('Date: ' . \gmdate('D, d M Y H:i:s') . ' GMT');
122124
$_GET['c'] = '';
123-
$uri = \ltrim(\urldecode(\parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)), '/');
124-
if (($uri == null || ! ($fe = \file_exists($this->basedir . '/../' . $uri))) && ($uri != 'favicon.ico')) {
125+
$uriInfos = (self::$uriInfos[$_SERVER['REQUEST_URI']] ??= self::parseURI($_SERVER['REQUEST_URI']));
126+
$uri = $uriInfos['uri'];
127+
if ($uriInfos['isAction']) {
125128
$_GET['c'] = $uri;
126129
} else {
127-
if ($fe) {
130+
if ($uriInfos['fe']) {
128131
Http::header('Content-Type: ' . (HttpCache::$header['Accept'] ?? 'text/html; charset=utf-8'), true);
129132
return $connection->send(\file_get_contents($this->basedir . '/../' . $uri));
130133
} else {
@@ -140,6 +143,16 @@ protected function handle(ConnectionInterface $connection, $datas) {
140143
return $connection->send(\ob_get_clean());
141144
}
142145

146+
protected static function parseURI($requestURI) {
147+
$uri = \ltrim(\urldecode(\parse_url($requestURI, PHP_URL_PATH)), '/');
148+
$isAction = ($uri == null || ! ($fe = \file_exists($this->basedir . '/../' . $uri))) && ($uri != 'favicon.ico');
149+
return [
150+
'uri' => $uri,
151+
'isAction' => $isAction,
152+
'file' => $fe
153+
];
154+
}
155+
143156
/**
144157
* Sets the worker count
145158
*

0 commit comments

Comments
 (0)