Skip to content

Commit 7eff149

Browse files
committed
fix TCP_NODELAY
1 parent d27d236 commit 7eff149

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

WebServer.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ public function initMimeTypeMap()
135135
if(preg_match("/\s*(\S+)\s+(\S.+)/", $content, $match))
136136
{
137137
$mime_type = $match[1];
138-
$extension_var = $match[2];
139-
$extension_array = explode(' ', substr($extension_var, 0, -1));
140-
foreach($extension_array as $extension)
138+
$workerman_file_extension_var = $match[2];
139+
$workerman_file_extension_array = explode(' ', substr($workerman_file_extension_var, 0, -1));
140+
foreach($workerman_file_extension_array as $workerman_file_extension)
141141
{
142-
self::$mimeTypeMap[$extension] = $mime_type;
142+
self::$mimeTypeMap[$workerman_file_extension] = $mime_type;
143143
}
144144
}
145145
}
@@ -151,57 +151,57 @@ public function initMimeTypeMap()
151151
* @param mixed $data
152152
* @return void
153153
*/
154-
public function onMessage($connection, $data)
154+
public function onMessage($connection)
155155
{
156156
// REQUEST_URI.
157-
$url_info = parse_url($_SERVER['REQUEST_URI']);
158-
if(!$url_info)
157+
$workerman_url_info = parse_url($_SERVER['REQUEST_URI']);
158+
if(!$workerman_url_info)
159159
{
160160
Http::header('HTTP/1.1 400 Bad Request');
161161
return $connection->close('<h1>400 Bad Request</h1>');
162162
}
163163

164-
$path = $url_info['path'];
164+
$workerman_path = $workerman_url_info['path'];
165165

166-
$path_info = pathinfo($path);
167-
$extension = isset($path_info['extension']) ? $path_info['extension'] : '' ;
168-
if($extension === '')
166+
$workerman_path_info = pathinfo($workerman_path);
167+
$workerman_file_extension = isset($workerman_path_info['extension']) ? $workerman_path_info['extension'] : '' ;
168+
if($workerman_file_extension === '')
169169
{
170-
$path = ($len = strlen($path)) && $path[$len -1] === '/' ? $path.'index.php' : $path . '/index.php';
171-
$extension = 'php';
170+
$workerman_path = ($len = strlen($workerman_path)) && $workerman_path[$len -1] === '/' ? $workerman_path.'index.php' : $workerman_path . '/index.php';
171+
$workerman_file_extension = 'php';
172172
}
173173

174-
$root_dir = isset($this->serverRoot[$_SERVER['HTTP_HOST']]) ? $this->serverRoot[$_SERVER['HTTP_HOST']] : current($this->serverRoot);
174+
$workerman_root_dir = isset($this->serverRoot[$_SERVER['HTTP_HOST']]) ? $this->serverRoot[$_SERVER['HTTP_HOST']] : current($this->serverRoot);
175175

176-
$file = "$root_dir/$path";
176+
$workerman_file = "$workerman_root_dir/$workerman_path";
177177

178-
if($extension === 'php' && !is_file($file))
178+
if($workerman_file_extension === 'php' && !is_file($workerman_file))
179179
{
180-
$file = "$root_dir/index.php";
181-
if(!is_file($file))
180+
$workerman_file = "$workerman_root_dir/index.php";
181+
if(!is_file($workerman_file))
182182
{
183-
$file = "$root_dir/index.html";
184-
$extension = 'html';
183+
$workerman_file = "$workerman_root_dir/index.html";
184+
$workerman_file_extension = 'html';
185185
}
186186
}
187187

188188
// File exsits.
189-
if(is_file($file))
189+
if(is_file($workerman_file))
190190
{
191191
// Security check.
192-
if((!($request_realpath = realpath($file)) || !($root_dir_realpath = realpath($root_dir))) || 0 !== strpos($request_realpath, $root_dir_realpath))
192+
if((!($workerman_request_realpath = realpath($workerman_file)) || !($workerman_root_dir_realpath = realpath($workerman_root_dir))) || 0 !== strpos($workerman_request_realpath, $workerman_root_dir_realpath))
193193
{
194194
Http::header('HTTP/1.1 400 Bad Request');
195195
return $connection->close('<h1>400 Bad Request</h1>');
196196
}
197197

198-
$file = realpath($file);
198+
$workerman_file = realpath($workerman_file);
199199

200200
// Request php file.
201-
if($extension === 'php')
201+
if($workerman_file_extension === 'php')
202202
{
203-
$cwd = getcwd();
204-
chdir($root_dir);
203+
$workerman_cwd = getcwd();
204+
chdir($workerman_root_dir);
205205
ini_set('display_errors', 'off');
206206
ob_start();
207207
// Try to include php file.
@@ -210,7 +210,7 @@ public function onMessage($connection, $data)
210210
// $_SERVER.
211211
$_SERVER['REMOTE_ADDR'] = $connection->getRemoteIp();
212212
$_SERVER['REMOTE_PORT'] = $connection->getRemotePort();
213-
include $file;
213+
include $workerman_file;
214214
}
215215
catch(\Exception $e)
216216
{
@@ -223,22 +223,22 @@ public function onMessage($connection, $data)
223223
$content = ob_get_clean();
224224
ini_set('display_errors', 'on');
225225
$connection->close($content);
226-
chdir($cwd);
226+
chdir($workerman_cwd);
227227
return ;
228228
}
229229

230230
// Static resource file request.
231-
if(isset(self::$mimeTypeMap[$extension]))
231+
if(isset(self::$mimeTypeMap[$workerman_file_extension]))
232232
{
233-
Http::header('Content-Type: '. self::$mimeTypeMap[$extension]);
233+
Http::header('Content-Type: '. self::$mimeTypeMap[$workerman_file_extension]);
234234
}
235235
else
236236
{
237237
Http::header('Content-Type: '. self::$defaultMimeType);
238238
}
239239

240240
// Get file stat.
241-
$info = stat($file);
241+
$info = stat($workerman_file);
242242

243243
$modified_time = $info ? date('D, d M Y H:i:s', $info['mtime']) . ' GMT' : '';
244244

@@ -259,7 +259,7 @@ public function onMessage($connection, $data)
259259
Http::header("Last-Modified: $modified_time");
260260
}
261261
// Send to client.
262-
return $connection->close(file_get_contents($file));
262+
return $connection->close(file_get_contents($workerman_file));
263263
}
264264
else
265265
{

Worker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ protected static function parseCommand()
605605
// Waiting amoment.
606606
usleep(100000);
607607
// Display statisitcs data from a disk file.
608-
readfile(self::$_statisticsFile);
608+
@readfile(self::$_statisticsFile);
609609
exit(0);
610610
case 'restart':
611611
case 'stop':
@@ -1406,7 +1406,7 @@ public function listen()
14061406
{
14071407
$socket = socket_import_stream($this->_mainSocket );
14081408
@socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, 1);
1409-
@socket_set_option($socket, SOL_SOCKET, TCP_NODELAY, 1);
1409+
@socket_set_option($socket, SOL_TCP, TCP_NODELAY, 1);
14101410
}
14111411

14121412
// Non blocking.

0 commit comments

Comments
 (0)