简体   繁体   English

从exec()调用时,PHP脚本会部分失败

[英]PHP script fails part-way through when called from exec()

I have a parent PHP script that can be executed from a browser. 我有一个可以从浏览器执行的父PHP脚本。 This spawns a child process via exec('/full/path/to/php -f /full/path/to/child_script.php args &> debug.log &') then returns a response to the browser. 这通过exec('/full/path/to/php -f /full/path/to/child_script.php args &> debug.log &')生成一个子进程,然后将响应返回给浏览器。 The child process generates a bunch of PDF files using Plates and mPDF. 子进程使用Plates和mPDF生成一堆PDF文件。 When called via exec from the browser, the child script gets about 10%-20% of the way through creating PDFs, then mysteriously stops without any output except for whatever echo statements I may have put in for debugging purposes. 当从浏览器中通过exec调用时,子脚本的创建过程大约占创建PDF的10%-20%,然后神秘地停止,没有任何输出,除了我可能出于调试目的而放入的任何echo语句。

  • the child script works when called from the CLI using the exact same command as used by the browser 孩子脚本作品使用完全相同的命令,从CLI调用时所使用的浏览器
  • the exec() call works on my local machine and our QA server, just not in production exec()调用可在我的本地计算机和QA服务器上使用,但不适用于生产环境
  • safe mode is off 安全模式已关闭
  • I have chmod 0777 'ed the child script and all the files/directories it operates on 我已经用chmod 0777编写了子脚本及其上运行的所有文件/目录
  • display_errors , log_errors , track_errors are all on display_errorslog_errorstrack_errors都在
  • error_reporting = E_ALL | E_STRICT
  • max_execution_time = 600
  • exec not in disable_functions exec不在disable_functions
  • called set_time_limit(0) in child script 在子脚本中称为set_time_limit(0)

I'm really stumped. 我真的很为难。 What might be causing this? 是什么原因造成的? Or what further steps should I take to debug? 还是应该采取进一步的步骤进行调试?

UPDATE UPDATE

The problem is not with the call to exec (or shell_exec ) itself, since I can call a parent script that then calls the main script via exec from the CLI. 问题不在于对exec (或shell_exec )本身的调用,因为我可以调用一个父脚本,然后再从CLI通过exec调用主脚本。 The problem only occurs when I try to execute via the web. 仅当我尝试通过网络执行时,才会出现此问题。

Some of the comments were on the right track. 一些评论是正确的。 After discussing this with my hosting company, it does appear that they are killing the script after 120 seconds CPU time. 与我的托管公司讨论此问题之后,看来他们在120秒的CPU时间后正在杀死该脚本。 This is why I was not getting any time limit error messages from PHP and the real execution time was not consistent. 这就是为什么我没有从PHP得到任何时间限制错误消息,并且实际执行时间不一致的原因。

My solution will be to refactor this as a cron job, where the server allows longer limits. 我的解决方案是将其重构为cron作业,其中服务器允许更长的限制。 Thanks all for the suggestions. 谢谢大家的建议。

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

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