PHP 7 将 php_http.dll 复制到 php/ext/ 不起作用?

PHP 7 copied php_http.dll into php/ext/ not working?

注意: 我应该补充一点,我不是在寻找 cURL 解决方案。我已经知道并且会使用 cURL。我想看看在我的 http 函数实验中会发生什么。

我 运行 PHP 7 来自 XAMPP 安装位置:

C:xampp\php

我下载了一个 Windows pecl-5.2.6-Win32.zip,里面全是 .dll 文件,然后我将 php_http.dll 文件复制到我的 php\ext文件夹,其中找到了所有其他 .dll。

我编辑了我的 php.ini 并按照所有其他扩展名的字母顺序添加了 extension=php_http.dll 行(好像这有什么不同)。

然后我重新启动了 Apache,并尝试执行 $response = http_get($url); 但得到错误 "Call to undefined function http_get()"。

似乎我的所有步骤都正确,但 http 功能无法正常工作。另外,我查看了我的 phpinfo() 并且没有看到任何对任何 PECL 扩展的引用。

更新: 我在另一个论坛上读到一个类似的问题,在 Apache error.log:

中找到了这一行

C:\xampp\php\ext\php_http.dll' - The specified module could not be found.

这个人说他降级了他的 php 版本,然后重复了这些步骤并且成功了。

昨晚我从 PHP 7 降级到 PHP 5.6。我重复将 .dll 复制到 /ext,在 php.ini 中启用 php_http.dll,然后得到一个不同的错误:

HP Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_http.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0

我找到了这些 Windows http extensions,再次复制了 .dll 文件,重新启动了 Apache,但现在我又回到了

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_http.dll' - The specified module could not be found.\r\n in Unknown on line 0

无需进行如此多的更改,您只需使用 curl 即可获得相同的结果。 http_get 上对 PECL 的引用已被删除。该版本的 PECL 适用于 PHP 5.2.x 。您使用的 php 是哪个版本?相反,您可以使用此功能

function url_get($url)
{
    $ch = curl_init();    // initialize curl handle
    curl_setopt($ch, CURLOPT_URL,$url); // set url to post 
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 10s
    $urlcontent = curl_exec($ch); 
    curl_close($ch); 
    return($urlcontent);
} 
$url = "example.com";
url_get($url);