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
;extension=php_http.dll
in yourphp.ini
file. Simply remove semicolons and after that restart your Apache Server. – S.I.