PECL_HTTP 已安装,但不起作用

PECL_HTTP is installed, but does not work

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

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]

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

请帮我看看为什么这个功能不可用

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

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

虽然在changelog中没有明确提及,但是在第二个版本中,程序风格完全被OOP风格所取代。

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 指向正确的位置。毫无疑问,他应该从 php.net/manual 中删除旧文档,或者至少更新它。

执行 HTTP GET 请求的新方法意味着使用 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 之前加载依赖项,因为它在 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