What is CLI Server?

I am using the php global getallheaders () function to get all the headers of the current request. The php manual for it says it is an alias for apache_request_headers and it becomes available on the CLI server. what is meant by a CLI server?

+3


source to share


2 answers


Since version 5.4.0, the PHP command line interpreter (CLI) also acts as an embedded web server .

command line parameters required to run the CLI as a web server:



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

      

The feature getallheaders()

apparently was not implemented on the embedded web server from the beginning, it was added in version 5.5.7

+4


source


With php bug # 66606 , built-in web server php header stores the value Content-Type

and Content-Length

in HTTP_CONTENT_TYPE

and HTTP_CONTENT_LENGTH

.

You can get these values ​​depending on the PHP_SAPI value:



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'];
    }
}

      

0


source







All Articles