PECL_HTTP 已安装,但不起作用 [英] PECL_HTTP is installed, but does not work

查看:70
本文介绍了PECL_HTTP 已安装,但不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 pecl_http,但是当我尝试使用它时,出现错误:

I have installed pecl_http, but when I try to use it, I get an error:

致命错误:未捕获的错误:调用/opt/lampp/htdocs/tes_http.php:3 中未定义的函数 http_get() 堆栈跟踪:#0 {main} 抛出在/opt/lampp/htdocs/tes_http.php on第 3 行

Fatal error: Uncaught Error: Call to undefined function http_get() in /opt/lampp/htdocs/tes_http.php:3 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/tes_http.php on line 3

这是我的php.ini配置:

extension="propro.so"
extension="http.so"
extension="raphf.so"
[PHP]

;;;;;;;;;;;;;;;;;;;

请帮我弄清楚为什么该功能不可用.

Please help me to figure out why the function is not available.

推荐答案

http 扩展的当前版本(package name is pecl_http) 不提供 http_get() 函数.此功能已在 2.0.0 版中删除(紧跟在 1.7.6 版之后).您可以通过在终端中运行以下命令来查看它:

The current version of http extension (the package name is pecl_http) doesn't provide http_get() function. This function has been removed in version 2.0.0 (right after version 1.7.6). You can see it by running the following commands in terminal:

git clone https://github.com/m6w6/ext-http.git
cd ext-http
git diff RELEASE_1_7_6 RELEASE_2_0_0

虽然在 changelog 中没有明确提及,但procedural style 在第二个版本中完全被OOP风格取代.

Although it is not mentioned explicitly in the changelog, the procedural style is completely replaced with OOP style in the second version.

PHP 官方网站上的文档 已过时.扩展的作者在他自己的网站上托管了新版本.我不会责怪他太多,因为 PECL 站点 上的文档链接指向正确的地点.毫无疑问,他应该从 php.net/manual 中删除旧文档,或者至少更新它.

The documentation on PHP's official site is obsolete. Extension's author hosted the new version on his own site. I wouldn't blame him much, as the link for documentation on the PECL site points to the right place. Undoubtedly, he should remove the old documentation from php.net/manual, or at least update it.

执行 HTTP GET 请求的新方法意味着使用 http\Client\Request 类:

The new way to perform HTTP GET requests implies the use of http\Client\Request class:

$request = new http\Client\Request("GET",
  "http://example.com",
  ["User-Agent"=>"MyAgent/0.1"]
);
$request->setOptions(["timeout" => 1]);

$client = new http\Client;
$client->enqueue($request)->send();

$response = $client->getResponse();

关于设置

您应该之前加载依赖项http.so,因为它在文档:

You should load the dependencies before http.so as it is recommended in the documentation:

; obligatory deps
extension = raphf.so
extension = propro.so

; if shared deps were enabled
extension = hash.so
extension = iconv.so
extension = json.so

; finally load pecl/http
extension = http.so

这篇关于PECL_HTTP 已安装,但不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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