0

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

1

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

Comments

-1

The problem is that you are not exiting the script once setting header. You would need to do something more like this

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

otherwise code after the header() will be run aswell

1 Comment

Thanks - that won't help either. I figured it out though, but can't answer my own question as a new user. Turns out the problem was the -f argument when calling php-cgi. Docs say "Implies -q", which suppresses headers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.