简体   繁体   English

为什么从PHP调用的长时间运行的Python脚本失败

[英]Why does a long running Python script called from PHP fail

I have a Python script which converts a PDF file. 我有一个Python脚本,可以转换PDF文件。 It is called via PHP in my Laravel app: 它在我的Laravel应用程序中通过PHP调用:

$command = escapeshellcmd("python /home/forge/default/pdf.py " . $id);
$output = shell_exec($command);

This works fine with any PDF up to 250MB, but fails with a larger PDF, for example 500Mb. 这适用于任何高达250MB的PDF, 但失败的是更大的PDF,例如500Mb。

If I call the Python script directly from the command line, it works fine and completes in around 5 minutes. 如果我直接从命令行调用Python脚本,它可以正常工作并在大约5分钟内完成。 It is only when called by shell_exec that it fails. 只有当shell_exec调用它才会失败。

This is happening in a Laravel queued job, so as far as I know is not using HTTP/PHP FPM, but the command line, which should have no timeout? 这是在Laravel排队的工作中发生的,所以据我所知,不是使用HTTP / PHP FPM,而是命令行,它应该没有超时?

The Laravel queue worker is running with timeout set to 0 (no timeout). Laravel队列工作程序正在运行,超时设置为0(无超时)。

Is there anything else in PHP CLI settings which could be causing this to fail? PHP CLI设置中还有什么可能导致此操作失败吗? Does anything know where errors would be recorded - there's nothing in failed_jobs tables, nothing in laravel.log , and nothing is caught by my Bugsnag integration. 有什么知道错误会记录在哪里 - 在failed_jobs表中没有任何内容, laravel.log没有任何内容,我的Bugsnag集成没有任何内容。

As it runs OK from the command line, I'm guessing it's not a Python issue but something to do with calling it from PHP. 因为它从命令行运行正常,我猜它不是Python问题,而是与从PHP调用它有关。

The server has 60Gb of RAM, and watching the process via htop , it never get above 3% of RAM usage. 服务器有60Gb的RAM,并通过htop观察进程,它永远不会超过3%的RAM使用率。 Could there be some other hard coded RAM limit? 可能有其他硬编码RAM限制吗?

I'm using Laravel 5.4, Ubuntu server, Python 2.7.12. 我正在使用Laravel 5.4,Ubuntu服务器,Python 2.7.12。

it's because there is an execution time and memory limit for script, you can check in the php.ini. 这是因为脚本有执行时间和内存限制,你可以在php.ini中查看。 usually it max_execute_time = 30s . 通常它max_execute_time = 30s and memory limit default 128M 和内存限制默认为128M

 ; Maximum execution time of each script, in seconds ; http://php.net/max-execution-time ; Note: This directive is hardcoded to 0 for the CLI SAPI max_execution_time = 300 

and memory limit 和内存限制

 ; Maximum amount of memory a script may consume (128MB) ; http://php.net/memory-limit memory_limit = 1280M 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM