“PHP Fatal error: Class 'HttpRequest' not

2020-01-25 07:56发布

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:

  • modified the PATH:

    $ echo "export PATH=/Applications/MAMP/bin/php/php5.5.3/bin:$PATH" >> ~/.profile`
    
  • verified that the paths for php, pear and pecl are correct:

    • /Applications/MAMP/bin/php/php5.3.6/bin/php is the path for php
    • /Applications/MAMP/bin/php/php5.3.6/bin/pear for pear
    • /Applications/MAMP/bin/php/php5.3.6/bin/pecl for pecl
  • I downloaded the source for php from the MAMP page (and checked that the version I downloaded was the same one I'm using, which is php5.5.3). Then I extracted the content and put it into /Applications/MAMP/bin/php/php5.5.3/include/php

  • Inside /Applications/MAMP/bin/php/php5.5.3/include/php I ran ./configure
  • I executed: pecl install pecl_http
  • I also added these extensions to the php.ini (initially, I modified the MAMP/bin/php/php5.5.3/conf/php.ini file):

    extension=raphf.so
    extension=propro.so
    extension="http.so"
    

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.

2条回答
相关推荐>>
2楼-- · 2020-01-25 08:32

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

查看更多
地球回转人心会变
3楼-- · 2020-01-25 08:47

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"];
查看更多
登录 后发表回答