PECL_HTTP无法识别php ubuntu [英] PECL_HTTP not recognised php ubuntu

查看:48
本文介绍了PECL_HTTP无法识别php ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用HttpRequest类,该类应该在php的PECL_HTTP扩展名中.我有php5,并使用以下代码安装pecl_http.

I am trying to use the HttpRequest class which should be in the PECL_HTTP extension of php. I have php5 and used the following to install 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:

After that i enter into my php.ini:

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

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

Then i restart my apache2 server, and try using the HttpRequest class, but it gives me the following error:

PHP Fatal error:  Class 'HttpRequest' not found

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

What are possible error's i might have missed?

更新 :(已更改标题)

扩展名未显示在phpinfo()中,我已设置

The Extension is not shown in phpinfo(), i set

extension=http.so

并检查 http.so 文件是否在我的 extension_dir 中.我真的不知道如何使php识别扩展名.

And checked if the http.so file is in my extension_dir. I really don't know how to make php recognise the extension.

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

UPDATE 2: I managed to install extension, but the class still does not exist. For others, i had to reference the other extensions pecl_http needs. (For me: propro.so, raphfr.so)

更新3 :我没有使班级可见,下面的答案显示了其他班级的一些方法.

UPDATE 3: I did not manage to make the Class visible, the answers below show some approaches with other classes.

我通过使用CURL解决了此问题.

I solved this issue by using CURL.

推荐答案

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

You have installed the new version of the extension which uses a completely different API. I still don't know how it works, but I will update my answer one I know. The Documentation of the new version is to be found at http://devel-m6w6.rhcloud.com/mdref/http.

要安装旧版本,请先卸载新版本,然后执行

To Install the old version, first uninstall the new verion and then execute

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

更新:以下是文档中的两个示例,两个示例都可以很好地工作:

UPDATE: here are two examples from the documentation, both should work well:

一个请求(可以在 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()返回响应的正文.

In both examples you can use $res->getBody() to return the body of the response.

我无法测试这些示例,但我听说其他人也可以使用.

I couldn't test these examples but I have heard of other people that they work.

这篇关于PECL_HTTP无法识别php ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆