2016-11-09 04:03
浏览 116


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

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

This is my php.ini configuration:



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

图片转代码服务由CSDN问答提供 功能建议

我已经安装了 pecl_http ,但是当我尝试使用它时,我收到一个错误 :

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

这是我的 php.ini 配置:

 <代码>扩展= “propro.so” 
extension = “http.so” 
extension = “raphf.so” \ N [PHP] 
 ;;;;;;  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;            / DIV>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duancilan5124 2016-11-09 05:08

    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

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

    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.

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

    $request = new http\Client\Request("GET",
    $request->setOptions(["timeout" => 1]);
    $client = new http\Client;
    $response = $client->getResponse();

    Regarding the setup

    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
    解决 无用
    打赏 举报

相关推荐 更多相似问题