duanpo1821 2016-11-09 04:03
浏览 116
已采纳

PECL_HTTP已安装,但不起作用

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:

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

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

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

  • 写回答

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",
      "http://example.com",
      ["User-Agent"=>"MyAgent/0.1"]
    );
    $request->setOptions(["timeout" => 1]);
    
    $client = new http\Client;
    $client->enqueue($request)->send();
    
    $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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line