Posts Tagged ‘XDebug’

Fetching headers sent by PHP from the command line

March 25th, 2010

I needed a way to unit test some code that sends HTTP headers via the header function.

However when doing this from the command line :

php -r "header('Foo : Bar'); print_r(headers_list());"

The only result you get is an empty array, which makes sense of course but for unit testing from the command line that is annoying.

XDebug saves the day again by providing the xdebug_get_headers function.

Let’s try the same code, but with XDebug this time :

php -r "header('Foo:Bar'); print_r(xdebug_get_headers());"

Returns

Array
(
 [0] => Foo:Bar
)

Joy :)

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)