webman升級(jí)到1.6后(workerman 為5.1),通過(guò)nginx轉(zhuǎn)發(fā)請(qǐng)求到webman,部分請(qǐng)求會(huì)出現(xiàn)504(nginx)側(cè)。在應(yīng)用系統(tǒng)中加debug代碼,發(fā)現(xiàn)請(qǐng)求已經(jīng)被執(zhí)行,在超過(guò)nginx的超時(shí)時(shí)間后,nginx 記錄504日志。直覺(jué)是在webman發(fā)送數(shù)據(jù)的時(shí)候,出現(xiàn)了異常。
public function get()
{
var_dump(1);
$user = $this->getUser();
unset($user['passhash']);
$workspace = $this->getWorkspaceModule()->getById($user['current_workspace_id']);
$role = $this->getWorkspaceMemberModule()->getMemberRole($user['id'], $workspace->id);
if (!$role) {
throw new AccessDeniedException();
}
$taskTypes = $this->getWorkspaceModule()->getWorkspaceTaskTypes($workspace->uuid);
$workspace->task_types = $taskTypes;
$user['workspace_role'] = $role;
$user['workspace'] = $workspace;
$user['workspaces'] = $this->getWorkspaceModule()->getUserWorkspaces($user['id'], ['id', 'uuid', 'name']);
foreach ($user['workspaces'] as $key => $w) {
if ($workspace->id == $w->id) {
unset($user['workspaces'][$key]);
break;
}
}
$user['workspaces'] = array_values($user['workspaces']->toArray());
var_dump(2);
return $this->json($user);
}
請(qǐng)求發(fā)起后,能夠在stdout中立即看到 var_dump 打出的1和2,表明業(yè)務(wù)代碼已經(jīng)執(zhí)行。
但是在nginx中,超過(guò)超時(shí)時(shí)間后,記錄504日志。
Nginx 日志
127.0.0.1 - - [26/Feb/2025:12:21:07 +0800] "GET /api/me HTTP/1.1" 504 569 "http://localhost:1314/w/e7361375-0390-4ec4-9784-e58e68aee8cd/s/47336567496380417/l/53479963810205697/l" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
Tcpdump抓包結(jié)果
無(wú)
操作系統(tǒng):MacOs
PHP版本:8.3.11
IO 庫(kù): Event
Nginx版本: nginx/1.25.4
Webman版本: v1.6.14
Workerman版本: 5.1
composer.json:
{
"name": "fade/app",
"type": "project",
"keywords": [
"high performance",
"http service"
],
"homepage": "http://wtbis.cn",
"license": "MIT",
"description": "High performance HTTP Service Framework.",
"config": {
"platform": {
"php": "8.1"
}
},
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://wtbis.cn",
"role": "Developer"
}
],
"support": {
"email": "walkor@workerman.net",
"issues": "https://github.com/walkor/webman/issues",
"forum": "http://wenda.workerman.net/",
"wiki": "http://workerman.net/doc/webman",
"source": "https://github.com/walkor/webman"
},
"require": {
"php": ">=8.1",
"workerman/webman-framework": "^v1.6.14",
"monolog/monolog": "^2.0",
"illuminate/database": "^v9.52.16",
"illuminate/redis": "^v9.52.16",
"vlucas/phpdotenv": "^5.6.1",
"ramsey/uuid": "^4.0",
"guzzlehttp/guzzle": "^7.2",
"workerman/crontab": "^1.0",
"davedevelopment/phpmig": "dev-master",
"twig/twig": "^3.3",
"symfony/console": "^v6.4.17",
"alibabacloud/ecs-20140526": "^3.0",
"alibabacloud/darabonba-openapi": "^0.2.8",
"alibabacloud/dysmsapi-20170525": "2.0.23",
"alibabacloud/sts-20150401": "^1.1",
"aliyuncs/oss-sdk-php": "^2.6",
"webman/redis-queue": "^1.3",
"illuminate/pagination": "^v9.52.16",
"webman/console": "^2.1.0",
"workerman/validation": "^3.0",
"godruoyi/php-snowflake": "^2.2",
"symfony/mailer": "^6.4",
"webman/log": "^1.2"
},
"suggest": {
"ext-event": "For better performance. "
},
"autoload": {
"files": [
"./support/helpers.php"
],
"psr-4": {
"": "./"
}
},
"scripts": {
"post-autoload-dump": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
},
"require-dev": {
"phpunit/phpunit": "^8.5"
}
}
Nginx配置
upstream app_api {
server 127.0.0.1:8787;
}
server {
listen 80;
server_name api.app.local;
client_max_body_size 20M;
access_log /var/log/nginx/app.access.com.log;
# other
gzip_static on;
location ^~ /api {
proxy_pass http://app_api;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header x-real-ip $proxy_add_x_forwarded_for;
}
}
感謝 @walkor 。 原來(lái)是安裝了swow擴(kuò)展,該擴(kuò)展和event擴(kuò)展有沖突,禁用掉swow擴(kuò)展以后,恢復(fù)正常了。