【问题标题】:Failed opening required 'HTTP/Request2.php' (include_path='.;C:\php5\pear')未能打开所需的 'HTTP/Request2.php' (include_path='.;C:\php5\pear')
【发布时间】:2011-05-27 20:48:45
【问题描述】:

每个人。我的梨有点麻烦。 我在我的localhost中测试(我的localhost路径是e:\www),我的系统是windows xp sp3,我的php版本是5.2.11,路径是C:\Program Files\phpStudy\PHP5,我在这个路径中运行go-pear.bat并完成安装pear , 现在梨路径在C:\Program Files\phpStudy\PHP5\PEAR(文件夹下包含.channels,.registry,OS,PEAR,.depdb,.depdblock,.filemap,; Windows: "\path1;\path2" include_path = ".;C:\Program Files\phpStudy\PHP5\PEAR" ,@9876 ),然后我运行C:\Program Files\phpStudy\PHP5\PEAR_ENV.reg并修改php.ini,

; Windows: "\path1;\path2"
include_path = ".;C:\Program Files\phpStudy\PHP5\PEAR"

重启 apache 后,我测试了一个从 pear 网站复制的简单代码。

<?php
require_once 'HTTP/Request2.php';

$request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET);
try {
    $response = $request->send();
    if (200 == $response->getStatus()) {
        echo $response->getBody();
    } else {
        echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
             $response->getReasonPhrase();
    }
} catch (HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?> 

但它会返回

Warning: require_once(HTTP/Request2.php) [function.require-once]: failed to open stream: No such file or directory in E:\www\ct\1.php on line 2

Fatal error: require_once() [function.require]: Failed opening required 'HTTP/Request2.php' (include_path='.;C:\php5\pear') in E:\www\ct\1.php on line 2

怎么了?怎么解决?谢谢。

【问题讨论】:

  • 您缺少文件 e:\www\HTTP\Request2.php

标签: php pear


【解决方案1】:

您需要安装 PEAR 包 http_request2。

你可以试试命令...

pear install http_request2

由 cweiske 提供,但它可能会失败并出现类似...的错误

Failed to download pear/http_request2 within preferred state 
"stable", latest release is version 0.5.2, stability "alpha", 
use "channel://pear.php.net/http_request2-0.5.2"

如果您看到该错误,则需要使用命令进行安装...

pear install "channel://pear.php.net/http_request2-0.5.2"

这可能会产生关于 Net_URL2 包的依赖错误,例如......

Failed to download pear/Net_URL2 within preferred state "stable", latest 
release is version 0.3.1, stability "beta", 
use "channel://pear.php.net/Net_URL2-0.3.1" to install
pear/HTTP_Request2 requires package "pear/Net_URL2" (version >= 0.2.0)

如果您看到这样的错误,请发出命令...

pear install "channel://pear.php.net/Net_URL2-0.3.1"

然后重新发出命令...

pear install "channel://pear.php.net/http_request2-0.5.2"

你应该准备好了。这些包的“状态”可能会随着时间而改变,因此上述命令中的确切版本也可能会改变,并且在某些时候命令 pear install http_request2 可能会开始自行工作。

祝你好运。

【讨论】:

  • 这个问题困扰了我很久,现在解决了,谢谢Night Owl
  • 感谢您的回答。它帮助我解决了在 Ubuntu Natty 上使用 Pear 安装 PHPUnit 时遇到的问题
  • 最棒的,尤其是关于使用pear install "channel 的小贴士……很管用。
  • 我对 windows Azure 上的 php 的 http/request2 有同样的问题。我运行所有它生成的所有命令“没有可用于 pacakage 的释放 ....
  • 仅供参考:必须 sudo 才能在我的一台机器上工作
【解决方案2】:

您需要从 pear 安装 HTTP_Request2 包:

pear install http_request2

那么它应该可以工作了。

【讨论】:

    【解决方案3】:

    我在 centos 上遇到过类似的问题。如果上面的事情不起作用,请按照这个补丁

    http://www.angeloluput.com/php-planet/pear-on-php-5-5-could-not-extract-package-xml

    补丁不起作用,所以我必须手动应用补丁。并且成功了。

    【讨论】:

      猜你喜欢
      • 2014-10-02
      • 2011-04-21
      • 2016-10-05
      • 2016-06-29
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      相关资源
      最近更新 更多