From 078cf5f339ebdbf6e93362bc44b983cfc4fab1c1 Mon Sep 17 00:00:00 2001 From: Link Date: Sat, 27 Jul 2019 17:35:37 +0800 Subject: [PATCH] fix keep-alived only on php --- WebServer.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/WebServer.php b/WebServer.php index 82ea77695..f529399f9 100644 --- a/WebServer.php +++ b/WebServer.php @@ -154,7 +154,11 @@ public function onMessage($connection) $workerman_url_info = parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); if (!$workerman_url_info) { Http::header('HTTP/1.1 400 Bad Request'); - $connection->close('

400 Bad Request

'); + if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") { + $connection->send('

400 Bad Request

'); + } else { + $connection->close('

400 Bad Request

'); + } return; } @@ -188,7 +192,11 @@ public function onMessage($connection) $workerman_root_dir_realpath) ) { Http::header('HTTP/1.1 400 Bad Request'); - $connection->close('

400 Bad Request

'); + if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") { + $connection->send('

400 Bad Request

'); + } else { + $connection->close('

400 Bad Request

'); + } return; } @@ -233,7 +241,11 @@ public function onMessage($connection) }else{ $html404 = '404 File not found

404 Not Found

'; } - $connection->close($html404); + if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") { + $connection->send($html404); + } else { + $connection->close($html404); + } return; } } @@ -249,7 +261,11 @@ public static function sendFile($connection, $file_path) // 304 Http::header('HTTP/1.1 304 Not Modified'); // Send nothing but http headers.. - $connection->close(''); + if (strtolower($_SERVER['HTTP_CONNECTION']) === "keep-alive") { + $connection->send(''); + } else { + $connection->close(''); + } return; } }