"PHP致命错误:找不到类'HttpRequest'" [英] "PHP Fatal error: Class 'HttpRequest' not found"
问题描述
我一直试图以多种方式解决此问题,阅读了很多文章,但仍然没有运气. 我在Mac,OSX 10.7 Lion上工作,并且正在使用MAMP为WordPress网站(php文件)编写插件,有一次我必须发出HTTP请求:
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)"
我已经安装了PEAR,PECL和HTTP扩展名(pecl_http),Xcode及其命令行工具. 这就是我所做的:
I've already installed PEAR, PECL and the HTTP extension (pecl_http), Xcode and its command line tools. This is what I did:
-
修改了PATH:
modified the PATH:
$ echo "export PATH=/Applications/MAMP/bin/php/php5.5.3/bin:$PATH" >> ~/.profile`
验证了php,pear和pecl的路径正确:
verified that the paths for php, pear and pecl are correct:
- /Applications/MAMP/bin/php/php5.3.6/bin/php是php的路径
- /Applications/MAMP/bin/php/php5.3.6/bin/pear for pear
- /Applications/MAMP/bin/php/php5.3.6/bin/pecl for pecl
我从MAMP页面下载了php的源代码(并检查我下载的版本是否与我使用的版本相同,即php5.5.3).然后,我提取内容并将其放入/Applications/MAMP/bin/php/php5.5.3/include/php
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
我还将这些扩展名添加到了php.ini中(最初,我修改了MAMP/bin/php/php5.5.3/conf/php.ini文件):
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"
关于最后一个引号:当我手动添加扩展名时,我是这样的:extension=http.so
.然后(尝试解决我的问题时),我尝试了另一种安装,该安装会自动修改php.ini,并在引号中加上扩展名.标记,但结果仍然相同,因此没有区别.
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.
所有这些之后,我停止了MAMP服务器并再次启动它,但是当我执行php时,仍然出现错误(在php_error.log中可见):
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
我主要关注该指南,其中包括: http://www. lullabot.com/blog/article/installing-php-pear-and-pecl-extensions-mamp-mac-os-x-107-lion
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.
推荐答案
该HttpRequest类由此PECL扩展的 v1 提供.
The class HttpRequest is provided by v1 of this PECL extension.
通过以下方式重新安装:$ pecl install -f pecl_http-1.7.6
Re-install via: $ pecl install -f pecl_http-1.7.6
不过,您可以在这里找到 v2 的文档: https://mdref.m6w6.name/http
You can find documentation for v2 here, though: https://mdref.m6w6.name/http
这篇关于"PHP致命错误:找不到类'HttpRequest'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!