【问题标题】:What is CLI server?什么是 CLI 服务器?
【发布时间】:2018-01-05 08:19:02
【问题描述】:

我正在使用 getallheaders() php 全局函数来获取当前请求的所有标头。 在 php 手册中,它说它是 apache_request_headers 的别名,它在 CLI 服务器中可用。 CLI 服务器是什么意思?

【问题讨论】:

标签: php apache codeigniter


【解决方案1】:

使用php's bug #66606,php 的内置网络服务器将Content-TypeContent-Length 标头值存储在HTTP_CONTENT_TYPEHTTP_CONTENT_LENGTH 字段中。

你可以根据PHP_SAPI的值来获取这些值:

if ('cli-server' === PHP_SAPI) {
    if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) {
         $content_length = $_SERVER['HTTP_CONTENT_LENGTH'];
    }
    if (array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
        $contentType = $_SERVER['HTTP_CONTENT_TYPE'];
    }
}

【讨论】:

    【解决方案2】:

    自 5.4.0 版起,PHP command line interpreter (CLI) 也可用作 built-in webserver

    启动 CLI 作为 Web 服务器所需的 command line options 是:

    -S <addr>:<port> Run with built-in web server.
    -t <docroot>     Specify document root <docroot> for built-in web server.
    

    getallheaders()这个功能显然从一开始就没有在内置的webserver中实现,它是在5.5.7版本中添加的

    【讨论】:

      猜你喜欢
      • 2017-05-21
      • 2012-06-01
      • 2018-11-25
      • 2012-04-28
      • 1970-01-01
      • 2019-02-25
      • 2011-01-09
      • 1970-01-01
      • 2020-08-24
      相关资源
      最近更新 更多