How could I stop PHP from returning headers when executed from commandline?

浪子不回头ぞ 提交于 2019-12-10 14:14:54

问题


This may be a ridiculous question, but it's been bothering me for a while. I have a mail forwarder piped to a PHP script, it receives perfectly, however I have the following error mailed back to me instantly:

A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

  pipe to |/home/[webroot]/public_html/external/mobile/email.php
    generated by mobile@[mydomain]

The following text was generated during the delivery attempt:

X-Powered-By: PHP/5.2.13 
Content-type: text/html

As you can see, Exim thinks the header response an error from the script I have. The script can receive the Email perfectly from php://stdin but Exim is quick-replying with the error.

Plus,

  • It's running from console, not Apache so HTAccess or configuring Apache most likely would do nothing.
  • I can not find any solution, or anyone with the same problem.

So my question is: How to I get rid of those two headers?

Thanks, ~Jonny

Edit, Source:

    #!/usr/bin/php
<?php
    $fd = fopen("php://stdin", "r");
        $email = "";
        while (!feof($fd)) {
         $email .= fread($fd, 1024);
        }
        fclose($fd);

        $dat = fopen(dirname(__FILE__).'/test.txt', 'w');
        fwrite($dat, $email);
        fclose($dat);

回答1:


looks like you're running php-cgi while you need php-cli (just "php"). Run php -v to make sure. If cgi is the case, try "-q" option.




回答2:


Had the same issue. My hosts told me I could use php-5.4-cli (normally I used php-5.4).

Adding -cli worked for me.



来源:https://stackoverflow.com/questions/2443575/how-could-i-stop-php-from-returning-headers-when-executed-from-commandline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!