当我从 PHP/Apache 调用 pdftk 而不是 PHP/CLI 或直接调用 pdftk 时,为什么会出现 SegFault

发布于 2024-09-25 22:36:49 字数 1404 浏览 0 评论 0原文

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

得不到的就毁灭 2024-10-02 22:36:49

php-cli & php-cgi(或模块,取决于您的服务器使用的内容)是不同的二进制文件。他们甚至不必共享相同的版本即可在您的服务器上幸福地并存。它们也可能不共享相同的配置。增加内存通常对解决段错误没有任何帮助。检查要点:

  1. 它们是否是同一版本?
  2. 它们是否具有相同的设置(查阅 phpinfo(); 输出中加载的 *.ini 位置,可能还有整个输出本身),如果不是:尝试更改您的设置会发生什么情况尽可能将 web 服务器迁移到 cli 的服务器。
  3. 段错误更多地发生在扩展中,而不是核心中,据我所知,有时看似无关。尝试一一禁用不需要的扩展,看看问题是否消失。
  4. 还是没有成功?您可能想使用 gdb 运行 apache,但我没有这方面的经验,但它可能会告诉您一些信息。
  5. 运气不好?重新编译您的网络服务器使用的 cgi 模块。

这是 RHEL4 上的 PHP 4.3.9。请不要开枪打我。

我为你感到难过多于愤怒,我们已经超过了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:

  1. Are they the same version?
  2. Do they have the same settings (consult the *.ini locations loaded in the 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.
  3. Segfaults occur more in extensions then in the core afaik, and sometimes seemingly unrelated. Try to disable unneeded extensions one by one to see if the problem goes away.
  4. Still no success? You may want to run apache with gdb, but I have no experience with that, it might tell you something though.
  5. No luck? Recompile either the module of cgi your webserver uses.

It's PHP 4.3.9 on RHEL4. Please don't shoot me.

I feel more sad for you then anger, we're beyond the 5.3 mark, come over, it's a lot more happy here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文