从命令行执行时,如何阻止PHP返回头文件? [英] How could I stop PHP from returning headers when executed from commandline?

查看:198
本文介绍了从命令行执行时,如何阻止PHP返回头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个荒谬的问题,但一直困扰着我一段时间。
我有一个邮件转发器管道到一个PHP脚本,它完美地收到,但是我立即发送以下错误邮件给我:

 code>您发送的消息无法传递给一个或多个收件人。这是一个永久的错误。以下地址失败:

管道到| / home / [webroot] /public_html/external/mobile/email.php
由mobile @ [mydomain]生成

以下文本在传递尝试期间生成:

X-Powered by:PHP / 5.2.13
内容类型:text / html

如你所见,Exim认为标题响应是我脚本中的一个错误。脚本可以从 php:// stdin 完整地收到电子邮件,但Exim正在快速回复错误。



Plus,




  • 从控制台运行,而不是Apache,所以HTAccess或配置Apache最有可能什么也不做。

  • 我可以没有找到任何解决方案,或任何有相同问题的人。



所以我的问题是:如何摆脱这两个标题?

谢谢,
〜Jonny



编辑,来源:

 #!/ 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);


解决方案

看起来你正在运行php-cgi,而你需要php-cli(只是php)。运行php -v来确保。如果是cgi,请尝试-q选项。


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);

解决方案

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.

这篇关于从命令行执行时,如何阻止PHP返回头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆