I am trying to use the HttpRequest class which should be in the PECL_HTTP extension of php. I have php5 and used the following to install pecl_http.
sudo pecl install pecl_http
pecl/pecl_http is already installed and is the same as the released version 2.0.1
install failed
After that i enter into my php.ini:
[PHP]
extension=http.so
[...]
Then i restart my apache2 server, and try using the HttpRequest class, but it gives me the following error:
PHP Fatal error: Class 'HttpRequest' not found
What are possible error's i might have missed?
UPDATE: (Changed the title)
The Extension is not shown in phpinfo(), i set
extension=http.so
And checked if the http.so
file is in my extension_dir
. I really don't know how to make php recognise the extension.
UPDATE 2:
I managed to install extension, but the class still does not exist.
For others, i had to reference the other extensions pecl_http needs. (For me: propro.so
, raphfr.so
)
UPDATE 3: I did not manage to make the Class visible, the answers below show some approaches with other classes.
I solved this issue by using CURL.
You have installed the new version of the extension which uses a completely different API. I still don't know how it works, but I will update my answer one I know. The Documentation of the new version is to be found at http://devel-m6w6.rhcloud.com/mdref/http.
To Install the old version, first uninstall the new verion and then execute
UPDATE: here are two examples from the documentation, both should work well:
one request (can be found at http://devel-m6w6.rhcloud.com/mdref/http/Client/enqueue):
multiple requests (can be found at http://devel-m6w6.rhcloud.com/mdref/http/Client/once):
In both examples you can use
$res->getBody()
to return the body of the response.I couldn't test these examples but I have heard of other people that they work.
I had the same problem and solved it by arrange the order in wich extensions are loaded in php.ini
All my other extensions was loaded using their own .ini files in
/etc/php5/mods_available
. In my apache2error.log
I noticed thatjson_decode
was needed byhttp.so
to load.I created a file for http (http.ini) and a symlink in
/etc/php5/apache/conf.d
with a higher prefix than json.my http.ini
use the new pecl_http.2.0.6 like this
or extend in your own class as extends http\Message