当我从 PHP/Apache 调用 pdftk 而不是 PHP/CLI 或直接调用 pdftk 时,为什么会出现 SegFault
当我在 Apache 中从 PHP 调用 /usr/local/bin/pdftk
时(通过 shell_exec()
、exec()
、system ()
、等),它会按预期返回 SYNOPSIS 消息。
当我通过 shell_exec()
调用 /usr/local/bin/pdftk input.pdf fill_form input.fdf output output.pdf flatten
时,没有任何返回。
当我将完全相同的字符串复制并粘贴到 shell 中的同一路径(作为 apache 用户)时,会按预期生成 output.pdf 文件。
将 pdftk
命令移至 PHP shell 脚本中(shebang 为 #!/usr/bin/php
)并使用 php script.php
执行它工作完美。
从 Apache 中的 PHP 调用该 shell 脚本(其 stderr 重定向到 stdout)(通过 shell_exec(script.php);)会导致这一行:
sh: line 1: 32547 Segmentation fault /usr/local/bin/pdftk input.pdf fill_form input.fdf output output.pdf flatten 2>&1
每当我从命令行运行脚本(通过 PHP或直接),它工作正常。每当我通过 Apache 通过 PHP 运行脚本时,它要么在没有任何通知的情况下失败,要么给出上面列出的 SegFault。
这是 RHEL4 上的 PHP 4.3.9。请不要开枪打我。我已使用 ini_set() 将内存设置为 512M,并确保 apache 用户已读/写所有路径(使用 fopen())并以 apache 身份登录...
刚刚去检查了 /var/log/messages找到这个:
Oct 4 21:17:58 discovery kernel: audit(1286241478.692:1764638):
avc: denied { read } for pid=32627 comm="pdftk" name="zero"
dev=tmpfs ino=2161 scontext=root:system_r:httpd_sys_script_t
tcontext=system_u:object_r:zero_device_t tclass=chr_file
注意:禁用 SELinux“修复”了该问题。这是否已成为 ServerFault 问题?有人可以给我 30 秒的 SELinux 访问控制入门吗?
When I call /usr/local/bin/pdftk
from PHP in Apache (via shell_exec()
, exec()
, system()
, etc.), it returns the SYNOPSIS message as expected.
When I call /usr/local/bin/pdftk input.pdf fill_form input.fdf output output.pdf flatten
via shell_exec()
, nothing returns.
When I copy and paste the exact same string to the same path in the shell (as the apache user), the output.pdf file is generated as expected.
Moving the pdftk
command into a PHP shell script (shebang is #!/usr/bin/php
) and executing it with php script.php
works perfectly.
Calling that shell script (with its stderr redirected to stdout) from PHP in Apache (via shell_exec(script.php);
) results in this line:
sh: line 1: 32547 Segmentation fault /usr/local/bin/pdftk input.pdf fill_form input.fdf output output.pdf flatten 2>&1
Whenever I run the script from the command line (via PHP or directly), it works fine. Whenever I run the script through PHP via Apache, it either fails without any notification or gives the SegFault listed above.
It's PHP 4.3.9 on RHEL4. Please don't shoot me. I've set memory to 512M with ini_set() and made sure that the apache user had read/write to all paths (with fopen()) and by logging in as apache ...
Just went and checked /var/log/messages to find this:
Oct 4 21:17:58 discovery kernel: audit(1286241478.692:1764638):
avc: denied { read } for pid=32627 comm="pdftk" name="zero"
dev=tmpfs ino=2161 scontext=root:system_r:httpd_sys_script_t
tcontext=system_u:object_r:zero_device_t tclass=chr_file
NOTE: Disabling SELinux "fixed" the problem. Has this moved into a ServerFault question? Can anybody give me the 30 second SELinux access controls primer here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
php-cli & php-cgi(或模块,取决于您的服务器使用的内容)是不同的二进制文件。他们甚至不必共享相同的版本即可在您的服务器上幸福地并存。它们也可能不共享相同的配置。增加内存通常对解决段错误没有任何帮助。检查要点:
phpinfo();
输出中加载的 *.ini 位置,可能还有整个输出本身),如果不是:尝试更改您的设置会发生什么情况尽可能将 web 服务器迁移到 cli 的服务器。我为你感到难过多于愤怒,我们已经超过了5.3分,过来吧,这里快乐多了。
php-cli & php-cgi (or the module, depends on what your server uses) are different binaries. They don't even have to share the same version to live happily side by side on your server. They also may not share the same configuration. Increasing memory usually does nothing to help Segfaults. Points to check:
phpinfo();
output, and possibly the whole output itself), if not: try what happens if you alter the one for your webserver to the one for the cli as far as possible.gdb
, but I have no experience with that, it might tell you something though.I feel more sad for you then anger, we're beyond the 5.3 mark, come over, it's a lot more happy here.