【问题标题】:PECL_HTTP not recognised php ubuntuPECL_HTTP 无法识别 php ubuntu
【发布时间】:2013-11-26 21:13:42
【问题描述】:

我正在尝试使用应该在 php 的 PECL_HTTP 扩展中的 HttpRequest 类。 我有php5并使用以下安装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

之后我进入我的 php.ini:

[PHP]
extension=http.so
[...]

然后我重新启动我的 apache2 服务器,并尝试使用 HttpRequest 类,但它给了我以下错误:

PHP Fatal error:  Class 'HttpRequest' not found

我可能错过了哪些可能的错误?

更新:(更改了标题)

扩展名没有显示在 phpinfo() 中,我设置了

extension=http.so

并检查http.so 文件是否在我的extension_dir 中。真不知道怎么让php识别扩展名。

更新 2: 我设法安装了扩展,但该类仍然不存在。 对于其他人,我不得不参考 pecl_http 需要的其他扩展。 (对我来说:propro.soraphfr.so

更新 3: 我没有设法让 Class 可见,下面的答案显示了其他类的一些方法。

我通过使用 CURL 解决了这个问题。

【问题讨论】:

  • phpinfo() 是否显示模块已启用?
  • 不,它没有。我真的不知道为什么。见更新
  • 您是否更新了正确的 php.ini 文件?
  • 我将phpinfo()中提到的php.ini文件修改为“加载配置文件”
  • apache 日志是怎么说的?

标签: php httprequest


【解决方案1】:

您已安装使用完全不同 API 的新版本扩展程序。我仍然不知道它是如何工作的,但我会更新我知道的答案。新版本的文档位于http://devel-m6w6.rhcloud.com/mdref/http

要安装旧版本,先卸载新版本再执行

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

更新:这是文档中的两个示例,两者都应该可以正常工作:

一个请求(可以在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();

多个请求(可以在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());
}

在这两个示例中,您都可以使用 $res-&gt;getBody() 返回响应的正文。

我无法测试这些示例,但我听说过其他人的工作。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,并通过在 php.ini 中加载扩展的顺序来解决它

    我的所有其他扩展都是使用 /etc/php5/mods_available 中的它们自己的 .ini 文件加载的。 在我的 apache2 error.log 中,我注意到 http.so 需要 json_decode 来加载。

    我为 http (http.ini) 创建了一个文件,并在 /etc/php5/apache/conf.d 中创建了一个符号链接,其前缀高于 json。

    我的 http.ini


    ; configuration for php http module
    ; priority=50
    
    extension=raphf.so
    
    extension=propro.so
    
    extension=http.so
    

    像这样使用新的 pecl_http.2.0.6

    new http\Message();
    

    或在您自己的类中扩展为 extends http\Message

    【讨论】:

      猜你喜欢
      • 2020-10-09
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      相关资源
      最近更新 更多