Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

http_parse_headers with PECL_HTTP

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

like image 542
Muaaz Khalid Avatar asked Jan 08 '16 05:01

Muaaz Khalid


2 Answers

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)
like image 90
Ricardo Velhote Avatar answered Sep 30 '22 10:09

Ricardo Velhote


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

like image 33
Muaaz Khalid Avatar answered Sep 30 '22 08:09

Muaaz Khalid