Search code examples
phphttp-headerscgifastcgi

Capture header in PHP-CGI


I'm attempting to get all HTTP header output from a PHP file, when run via php-cgi. From everything I've read, php-cgi is supposed to output all headers by default. (There's even an option to suppress this, as though it happens automatically.)

I have a PHP file named "test.php", with the following contents:

header('Location: http://stackoverflow.com');
echo 'test';

But when I run it:

php-cgi -f test.php

The output is simply:

test

I expected the location header to be output first. How can I get this header info? I'm using PHP 5.5.3-1ubuntu2.3 (cgi-fcgi).


Solution

  • I got it! I noticed in the doc definition for the -f argument that it "Implies '-q'".

    So this is the solution:

    php-cgi test.php
    

    (Without the -f argument)