Laravel 工作投入 Symfony\Component\Process\Exception\ProcessTimedOutException

Laravel Job throwing Symfony\Component\Process\Exception\ProcessTimedOutException

我的 Web 应用程序运行一个作业,使用 aminyazdanpanah/php-ffmpeg-video-streaming 包将视频转换为 HLS。然而,大约 2 分钟后,作业失败并抛出错误:

Symfony\Component\Process\Exception\ProcessTimedOutException: The process '/usr/bin/ffmpeg -y -i...'
exceeded the timeout of 300 seconds. in /var/www/vendor/symfony/process/Process.php:1206

Laravel 作业的超时设置为 7200 秒。 我的主管设置还指定了 7200 秒的超时:

[program:app_worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan queue:work --tries=1 --timeout=7200 --memory=2000
autostart=true
autorestart=true

我还在 ini 文件中将 php max_execution_time 设置为 7200s。 在作业 handle() 函数中,我还调用了 set_time_limit(7200); 来设置时间限制。

我已经重新启动了队列工作器并清除了我的缓存,但这似乎并没有解决问题。

似乎 Symfony 只是忽略了 Laravel 的超时规范。

我注意到它在大约 2 分钟后失败了,因为在我的 config/queue.php 文件中,redis retry_after 被设置为 90。

 'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => env('REDIS_QUEUE', 'default'),
            'retry_after' => 90,
            'block_for' => null,
            'after_commit' => false,
        ],

我将其增加到 3600,因此作业在 2 分钟后停止失败,但在 300 秒后仍然失败。

我后来追踪到超时来自 aminyazdanpanah/php-ffmpeg-video-streaming FFmpeg::create()。 默认情况下,函数设置 300s 的超时。所以我不得不将配置传递给函数以增加超时时间:

use Streaming\FFMpeg;

$ffmpeg =  FFMpeg::create([
            'timeout'          => 3600,
        ]);

这解决了超时问题。