解决thinkphp消息队列超时问题,think\process\exception\Timeout和Maximum execution time of 120 seconds exceeded报错

 问题:

今天在消息队列的fire里调用第三方api,api响应时间比较长,于是出现了报错:

PS D:\project\server> php think queue:listen
Bce任务开始... story_id: 7



  [think\process\exception\Timeout]
  The process ""C:\phpstudy_pro\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe" think queue:work --queue="default" -
  -delay=0 --memory=128 --sleep=3 --tries=0" exceeded the timeout of 60 seconds.
  
  
    [think\exception\ErrorException]
  Maximum execution time of 120 seconds exceeded


PS D:\project\server> php think queue:listen --timeout=1800
Bce任务开始... story_id: 7

Exception trace:
 () at D:\project\server\application\common\services\BaseService.php:48
 think\Error::appShutdown() at n/a:n/a

如上,加了超时时间参数、修改php.ini里的超时配置几分钟后还是继续报超时。

解决方案:

1. 修改PHP配置文件(推荐)

找到PHP的php.ini文件,修改:

max_execution_time = 1800

由于消息队列是泡在命令行里,所以重启窗口,不需要重启PHP服务。

2. 在代码中动态设置

set_time_limit(1800); // 0表示不限制

3.关闭Xdebug的远程超时限制

找到Xdebug相关配置并修改:

; 增加或修改以下配置
xdebug.remote_timeout = 1800  ; 原来是200秒,改为1800秒
; 或者直接关闭远程自动启动(如果在CLI下不需要调试)
xdebug.remote_autostart = Off
xdebug.remote_enable = Off

4.检查MySQL连接超时

修改数据库配置或者在MySQL中执行:

SET SESSION max_execution_time = 1800000; -- 毫秒单位
SET SESSION wait_timeout = 1800;
SET SESSION interactive_timeout = 1800;

再次运行php think queue:listen --timeout=1800终于不超时了!

posted @ 2026-05-30 12:15  我的五年  阅读(15)  评论(0)    收藏  举报