0

I have the following code

protected function parse($header) { $headerArr = http_parse_headers($header); foreach ($headerArr as $key => $value) { echo $key.'=>'.$value; } }

where $header is a http header. This code is in a PHP Class in a symfony2 project. I can execute it in a browser an get the expected results the keys and values of the parsed header like this

  • Response Code=>200
  • Response Status=>OK
  • Date=>Sun, 13 Jul 2014 21:39:51 GMT
  • Server=>Apache/2.4.7 (Ubuntu)
  • Last-Modified=>Wed, 26 Mar 2014 22:51:46 GMT
  • Etag=>502-4f58a50290480
  • Accept-Ranges=>bytes
  • Content-Length=>1282
  • Content-Disposition=>attachment; filename= mvc.zip
  • Keep-Alive=>timeout=5, max=100
  • Connection=>Keep-Alive
  • Content-Type=>application/zip

The problem is when i try to run a unit test for the function parse(), the PHPUnit can't find the http_parse_headers() function an throws "PHP Fatal error: Call to undefined function http_parse_headers()

How is this posible? How can I fix it?

1 Answers1

0

A quick search of the PHP manual shows that http_parse_headers is part of a pecl extension: PECL pecl_http >= 0.10.0

Your server and your command line php versions must be different. The php manual has a work around but hopefully you can just update your command line version.

Cerad
  • 48,157
  • 8
  • 90
  • 92
  • My server is my own computer, so I'm running the command line in the same place than my server. My PHP version showed by php - version command is PHP 5.5.9-1ubuntu4 (cli) (built: Apr 9 2014 17:08:27) – Jorge Miralles Sep 04 '14 at 20:05