【问题标题】:Run PHP-CLI Without Quiet Mode在没有安静模式的情况下运行 PHP-CLI
【发布时间】:2018-08-29 14:37:39
【问题描述】:

似乎默认情况下,PHP-CLI 现在仅在安静模式下运行,而不是要求用户通过 -q--no-header

例如,如果phptest.php 如下:

<?php header("Location: http://www.something.com"); ?>

我们可以使用 cURL 和 Apache 服务器请求它,结果如下:

$ curl -I "http://localhost/phptest.php"

HTTP/1.1 302 Found
Date: Tue, 20 Mar 2018 16:47:48 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.24
Location: http://www.something.com
Content-Type: text/html

但是如果我们通过 PHP-CLI 请求,我们什么也得不到:

$ php /var/www/phptest.php

那么,我的问题是如何让 PHP-CLI 也返回标头?如果不可能,有哪些替代方案(没有 cURLing 或 wgeting 它)?

【问题讨论】:

    标签: php


    【解决方案1】:

    使用php-cgi 代替php

    $ php-cgi /var/www/phptest.php
    
    Status: 302 Moved Temporarily
    X-Powered-By: PHP/5.6.32
    Location: http://www.something.com
    Content-type: text/html; charset=UTF-8
    

    【讨论】:

      猜你喜欢
      • 2016-03-01
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      相关资源
      最近更新 更多