webman升级到1.6后(workerman 为5.1),通过nginx转发请求到webman,部分请求会出现504(nginx)侧。在应用系统中加debug代码,发现请求已经被执行,在超过nginx的超时时间后,nginx 记录504日志。直觉是在webman发送数据的时候,出现了异常。
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);
}
请求发起后,能够在stdout中立即看到 var_dump 打出的1和2,表明业务代码已经执行。
但是在nginx中,超过超时时间后,记录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抓包结果
无
操作系统:MacOs
PHP版本:8.3.11
IO 库: 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://www.workerman.net",
"license": "MIT",
"description": "High performance HTTP Service Framework.",
"config": {
"platform": {
"php": "8.1"
}
},
"authors": [
{
"name": "walkor",
"email": "walkor@workerman.net",
"homepage": "http://www.workerman.net",
"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;
}
}
按照webman文档upstream李加个keepalive试下
加了没用。生产环境上没有这个,同样的版本,只是操作系统不一样。
感谢 @walkor 。 原来是安装了swow扩展,该扩展和event扩展有冲突,禁用掉swow扩展以后,恢复正常了。