8

I wanted to use http_parse_headers So, I've installed dependency pecl_http(2.4.3/2.2.5) and call http_parse_headers function with no success.

function_exists() always fails is there anything that I'm missing here?

I'm using

CentOS 6.7 (Final)

Apache 2.4.16

PHP 5.6

Update 1

Here is the Code!

<?PHP
    if(function_exists("http_parse_headers")) echo 'Function Exists';
    else echo 'Function Not Exists';
?>

Update 2

here is the php.ini

......
......
extension=pdo.so
extension=pdo_sqlite.so
extension="memcache.so"
extension="raphf.so"
extension="propro.so"
extension="http.so"
extension=pdo_mysql.so

Update 3

Here is the output of phpinfo()

output of phpinfo()

Muaaz Khalid
  • 2,199
  • 2
  • 28
  • 51
  • had you restarted apache after installation? – Chetan Ameta Jan 08 '16 at 05:39
  • Yes I've restarted using `service httpd restart` – Muaaz Khalid Jan 08 '16 at 05:41
  • Did you enable it in your php.ini? Add these: extension=raphf.so, extension=propro.so, extension=http.so – Clay Jan 08 '16 at 05:42
  • Yes, please check update 2 – Muaaz Khalid Jan 08 '16 at 05:47
  • Does adding curly braces help? `` ref: http://php.net/manual/en/function.function-exists.php and as shown in: http://php.net/manual/en/function.http-parse-headers.php does `print_r(http_parse_headers($headers));` show anything? Maybe this might help http://stackoverflow.com/questions/6368574/how-to-get-the-functionality-of-http-parse-headers-without-pecl – Steve Jan 08 '16 at 15:17
  • @Steve Please read the question carefully. If you don't have a solution. Avoid commenting. – Muaaz Khalid Jan 08 '16 at 15:23
  • check the output of `phpinfo()` or `get_loaded_extensions()` or do `php -ri http` on the cli. does it list the extension? If it doesn't list the extension, make sure you edited the right php.ini, e.g. the one that is given in `phpinfo()`. – Gordon Jan 10 '16 at 10:59
  • Yes, I've checked using `get_loaded_extensions()` and all the following extensions are loaded `raphf, propro, http`. Although, `php -ri http` gives following output `Parse error: syntax error, unexpected end of file in Command line code on line 1` – Muaaz Khalid Jan 10 '16 at 12:37

2 Answers2

8

The PHP docs are incorrect. Version 2 of the library is incompatible with the functions listed in php.net.

Reading the new documentation you now have to use HTTP::parse as such:

http\Header::parse($yourHeaders)
Ricardo Velhote
  • 4,630
  • 1
  • 24
  • 30
1

Ok, After a long long search I found that

Version 2 of PECL_HTTP library is COMPLETELY INCOMPATIBLE with Version 1 None of the HTTP functions exists in Version 2

This is NOT stated ANYWHERE in the docs on PHP.net.

By the way, Version 2 is a completely OOP interface and drops support for all the functions listed here in the docs.

If you are looking for the functional API, use Version 1

So, as suggested by Ricardo you need to use

http\Header::parse($yourHeaders);

to parse header and

new http\Cookie($yourCookies);

to parse cookie etc

Muaaz Khalid
  • 2,199
  • 2
  • 28
  • 51