2

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.

9
  • 1
    Does phpinfo() show the module as enabled? Commented Nov 26, 2013 at 22:10
  • No, it does not. And i really don't know why. See Update Commented Nov 27, 2013 at 7:23
  • Did you update the correct php.ini file? Commented Nov 27, 2013 at 7:32
  • I modified the php.ini file that is mentioned in phpinfo() as "Loaded Configuration File" Commented Nov 27, 2013 at 9:08
  • 1
    what does the apache log say? Commented Nov 27, 2013 at 9:14

2 Answers 2

4

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

pecl install http://pecl.php.net/get/pecl_http-1.7.6.tgz

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

<?php
(new http\Client)->enqueue(new http\Client\Request("GET", "http://php.net"), 
    function(http\Client\Response $res) {
        printf("%s returned %d\n", $res->getTransferInfo("effective_url"), $res->getResponseCode());
        return true; // dequeue
})->send();

multiple requests (can be found at http://devel-m6w6.rhcloud.com/mdref/http/Client/once):

<?php
$client = new http\Client;
$client->enqueue(new http\Client\Request("HEAD", "http://php.net"));
$client->enqueue(new http\Client\Request("HEAD", "http://pecl.php.net"));
$client->enqueue(new http\Client\Request("HEAD", "http://pear.php.net"));

printf("Transfers ongoing");
while ($client->once()) {
    // do something else here while the network transfers are busy
    printf(".");
    // and then call http\Client::wait() to wait for new input
    $client->wait();
}
printf("\n");

while ($res = $client->getResponse()) {
    printf("%s returned %d\n", $res->getTransferInfo("effective_url"),
        $res->getResponseCode());
}

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 apache2 error.log I noticed that json_decode was needed by http.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


; configuration for php http module
; priority=50

extension=raphf.so

extension=propro.so

extension=http.so

use the new pecl_http.2.0.6 like this

new http\Message();

or extend in your own class as extends http\Message

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.