PECL_HTTP无法识别php-ubuntu


PECL_HTTP not recognised php ubuntu

我正在尝试使用HttpRequest类,该类应该在php的PECL_HTTP扩展中。我有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:我没有设法让课堂可见,下面的答案显示了其他课堂的一些方法。

我使用CURL解决了这个问题

您已经安装了使用完全不同的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->getBody()返回响应的正文。

我无法测试这些例子,但我听说过其他人也能做到。

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

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

我在/etc/php5/apache/conf.d中创建了一个http(http.ini)文件和一个前缀比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