-2

NOTE: I should add that I'm not fishing for a cURL solution. I already know and do cURL. I want to see what happens in my experiment with an http function.

I'm running PHP 7 from a XAMPP installation at:

C:xampp\php

I downloaded a Windows pecl-5.2.6-Win32.zip, which was full of .dll files, then I copied the php_http.dll file into my php\ext folder, where all the other .dlls were found.

I edited my php.ini and added the line extension=php_http.dll in the alphabetical order of all the other extensions (as if that makes any difference).

Then I restarted Apache, and tried to perform a $response = http_get($url); but get the error "Call to undefined function http_get()".

Seems like I'm doing all the steps right, but the http functions just aren't working. Also, I looked at my phpinfo() and I don't see any reference to any PECL extension.

UPDATE: I read in another forum a similar problem, where this line was found in the Apache error.log:

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

The individual said he downgraded his php version, then repeated the steps and it worked.

Last night I downgraded from PHP 7 to PHP 5.6. I repeated the .dll copy to /ext, enabled php_http.dll in php.ini, and then got a different error:

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

I found these Windows http extensions, again copied the .dll file, restarted Apache, but now I'm back to

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

TARKUS
  • 2,170
  • 5
  • 34
  • 52

1 Answers1

2

Instead of doing so many changes you could have simply used curl and get the same result. Reference to PECL on http_get has been removed. That version of PECL is for PHP 5.2.x . Which version of php you are using? instead you can use this function

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);
Amit Ray
  • 3,445
  • 2
  • 19
  • 35
  • I've been using cURL extensively for this project. I'm not asking for a cURL solution. I want to see what happens with an http function. – TARKUS Aug 20 '16 at 11:53
  • @InfiniteLoop If you have read my answer I already stated that it works in php 5.2.x. But I dont know which version of PHP you are trying with? – Amit Ray Aug 20 '16 at 12:06
  • Ah, sorry. I rolled back from PHP 7 (doesn't seem to be a PECL out there for 7) to PHP 5.6. Still getting `Unable to load dynamic library 'C:\xampp\php\ext\php_http.dll' - The specified module could not be found.` error. The extension seems to be made for this version. I might have to keep rolling back to earlier PHP versions until one works? – TARKUS Aug 20 '16 at 12:11
  • It's possible this is an exercise in futility, as I'm not sure it's worth it to keep rolling back my PHP version just to get an outdated function to work. – TARKUS Aug 20 '16 at 12:16
  • 1
    @InfiniteLoop I would suggest not to waste time on this as I am unable to even find a reference of the method http_get in any official sites php.net or PECL sites. If your purpose is not solved by curl there may be some other means to achieve that. – Amit Ray Aug 20 '16 at 12:19