Search code examples
phppecl

PHP 7 copied php_http.dll into php/ext/ not working?


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


Solution

  • 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);