首页 > 解决方案 > php pecl_http 已加载,但未定义任何函数

问题描述

我正在尝试使用http_build_str()andhttp_build_url()函数。我已经安装并启用了 pecl_http,但我仍然收到此错误:

Call to undefined function http_build_str()

我已经上下验证了扩展程序已安装并启用。如果他们的权限设置错误,我也已经遇到过那种警告消息,所以我也可以排除这种情况。

然后我遇到了 extension_loaded()get_extension_funcs()。他们的结果有点令人困惑:

print_r(extension_loaded('http')); // true
print_rt(get_extension_funcs('http')); // []

进行完整性检查后,我针对我知道有效的不同扩展运行了这些函数,并且确实在函数数组中得到了一些结果。如您所见,“http_build_str”和“http_build_url”并不是get_extension_funcs()我所期望的输出的一部分。有人可以帮忙吗?

万一这很重要,我将其设置在 Docker 容器中,我认为其配置的相关部分如下:

RUN apt-get update && apt-get install --no-install-recommends -y \
    git-core \
    build-essential \
    openssl \
    libssl-dev \
    libcurl4-openssl-dev

RUN docker-php-ext-install pdo_mysql mbstring exif zip pcntl ftp
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN pecl install propro raphf \
    && docker-php-ext-enable propro raphf \
    && rm -rf /tmp/pear
RUN pecl install pecl_http xdebug \
    && docker-php-ext-enable http xdebug \
    && rm -rf /tmp/pear

标签: phphttpmodulephp-extensionpecl

解决方案


似乎 PHP Manuel 在这个上有点过时了。不知道我是怎么错过的,但是这个问题是http.so loaded but http_get undefined的副本。

评论中回答这个问题的链接已经死了,官方文档似乎已经移动了。 https://mdref.m6w6.name/http/QueryString

似乎功能仍然存在,只是现在以几个类的形式而不是函数的形式。

$params = ['test1'=>'val1','test2'=>'val2'];
$queryHandler = new QueryString($params);
$queryString = (string)$queryHandler;
print_r($queryString); // test1=val1&test2=val2

推荐阅读