![PHP 致命错误:超出最大执行时间 0 秒](https://linux22.com/image/611865/PHP%20%E8%87%B4%E5%91%BD%E9%94%99%E8%AF%AF%EF%BC%9A%E8%B6%85%E5%87%BA%E6%9C%80%E5%A4%A7%E6%89%A7%E8%A1%8C%E6%97%B6%E9%97%B4%200%20%E7%A7%92.png)
我有一个 PHP 应用程序,它使用 pdf2htmlEX 和 HTMLpurifier 将 pdf 文档转换为文本格式。转换过程包括几个步骤:
1. 使用 Web 浏览器上传书籍
2. 使用 pdf2htmlex 将 pdf 转换为 txt
3. 使用 HTMLPurifer 处理 txt 文件
对于大多数文档,一切都正常运行,但对于一些包含大量页面(超过 230 页)的文档,步骤 3 会失败。HTMLpurifier 处理页面时会引发错误:“PHP 致命错误:超出最大执行时间 0 秒”。在我的配置中,max_execution_time 设置为 0。我已将 strace 附加到 Apache 进程,以下是终止前的输出:
lstat("/tmp/books/3349/html/78.page", {st_mode=S_IFREG|0644, st_size=40165, ...}) = 0
open("/tmp/books/3349/html/78.page", O_RDONLY) = 20
fstat(20, {st_mode=S_IFREG|0644, st_size=40165, ...}) = 0
lseek(20, 0, SEEK_CUR) = 0
fstat(20, {st_mode=S_IFREG|0644, st_size=40165, ...}) = 0
read(20, "<div class=\"pd w1 h1\"><div id=\"p"..., 8192) = 8192
read(20, "AACAsAQAAQFgCAAAgLAEAABCWAAAACEs"..., 8192) = 8192
read(20, "7\"><span class=\"_ _1f\"> </span>F"..., 8192) = 8192
read(20, "class=\"_ _8\"> </span>of<span cla"..., 8192) = 8192
read(20, "/span></div><div class=\"t m1 x7a"..., 8192) = 7397
read(20, "", 8192) = 0
read(20, "", 8192) = 0
close(20) = 0
lstat("/tmp/books/3349/text/78.txt", 0x7fff115a43f0) = -1 ENOENT (No such file or directory)
open("/tmp/books/3349/text/78.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 20
fstat(20, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
lseek(20, 0, SEEK_CUR) = 0
write(20, "66 2. TOPOSESa \357\254\201xed space is a"..., 2157) = 2157
close(20) = 0
lstat("/tmp/books/3349/html/79.page", {st_mode=S_IFREG|0644, st_size=48214, ...}) = 0
open("/tmp/books/3349/html/79.page", O_RDONLY) = 20
fstat(20, {st_mode=S_IFREG|0644, st_size=48214, ...}) = 0
lseek(20, 0, SEEK_CUR) = 0
fstat(20, {st_mode=S_IFREG|0644, st_size=48214, ...}) = 0
read(20, "<div class=\"pd w1 h1\"><div id=\"p"..., 8192) = 8192
read(20, "AWAIAACAsAQAAYN5hAoBPSWIEdtXWCAD"..., 8192) = 8192
read(20, "=\"_ _0\"></span>oof<span class=\"f"..., 8192) = 8192
read(20, "c\"></span>).</span></div><div cl"..., 8192) = 8192
read(20, "lass=\"_ _23\"> </span>sho<span cl"..., 8192) = 8192
read(20, "ls0 ws0 r0\">F<span class=\"ff4\"><"..., 8192) = 7254
read(20, "", 8192) = 0
read(20, "", 8192) = 0
close(20) = 0
--- SIGPROF (Profiling timer expired) @ 0 (0) ---
有趣的是 - 我在同一个系统配置中有两个环境 - 一个在 AWS 中,另一个在 VirtualBox 中的 VM 中。两者都有 Ubuntu 12.04 + Apache 2.2 + PHP 5.4.13,配置设置相同,但问题仅发生在 AWS 节点上。有什么想法吗?
答案1
这是因为 max_input_time 选项的值设置得太小。当我增加它时,问题就消失了。这个 PHP 错误消息非常具有误导性。