chechab
chechab

Reputation: 101

"PHP Fatal error: Class 'HttpRequest' not found"

I've been stuck trying to solve this problem in many ways, reading a lot of posts but still having no luck. I work on a Mac, OSX 10.7 Lion, and I'm writing a plugin for a WordPress site (php files) using MAMP, and at one point I have to make an HTTP request:

$request = new HttpRequest('something'); 
$request->setMethod(HTTP_METH_GET);

There's an error when executing this request and when I checked the log file, here's the message:

"PHP Fatal error:  Class 'HttpRequest' not found in (the_php_file)"

I've already installed PEAR, PECL and the HTTP extension (pecl_http), Xcode and its command line tools. This is what I did:

About that last one in quotation marks: when I added the extension manually, I did it like this: extension=http.so. Then (when trying to fix my problem) I tried an alternative installation that modified the php.ini automatically, and wrote the extension with the quot. marks, but the result was still the same, so it didn't make a difference.

After all of this, I stopped the MAMP server and started it again, but when I executed the php I still got the error (visible in the php_error.log):

PHP Fatal error:  Class 'HttpRequest' not found

I've been following this guide mostly, among so many more: http://www.lullabot.com/blog/article/installing-php-pear-and-pecl-extensions-mamp-mac-os-x-107-lion

I'd appreciate any idea because I've run out of them.

Upvotes: 10

Views: 54928

Answers (2)

m6w6
m6w6

Reputation: 656

The class HttpRequest is provided by v1 of this PECL extension.

Re-install via: $ pecl install -f pecl_http-1.7.6

You can find documentation for v2 here, though: https://mdref.m6w6.name/http

Upvotes: 26

tony gil
tony gil

Reputation: 9564

alternatively, in case you cannot control certain environmental variables or install packages, you might try using curl which should return a json object (below is a working snippet of a google api call).

$url = 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=TOKEN_DATA_123';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$json = json_decode($response, true);
curl_close($ch);
print_r($json);
$userEmail = $json["email"];

Upvotes: 3

Related Questions