php libcurl alternative php libcurl alternative curl curl

php libcurl alternative


To fetch content via HTTP, first, you can try with file_get_contents ; your host might not have disabled the http:// stream :

$str = file_get_contents('http://www.google.fr');

Bit this might be disabled (see allow_url_fopen) ; and sometimes is...


If it's disabled, you can try using fsockopen ; the example given in the manual says this (quoting) :

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);if (!$fp) {    echo "$errstr ($errno)<br />\n";} else {    $out = "GET / HTTP/1.1\r\n";    $out .= "Host: www.example.com\r\n";    $out .= "Connection: Close\r\n\r\n";    fwrite($fp, $out);    while (!feof($fp)) {        echo fgets($fp, 128);    }    fclose($fp);}

Considering it's quite low-level, though (you are working diretly with a socket, and HTTP Protocol is not that simple), using a library that uses it will make life easier for you.

For instance, you can take a look at snoopy ; here is an example.


You can write a plain curl server script with PHP and place it on curl-enabled hosting, and when you need curl - you make client calls to it when needed from curl-less machine, and it will return data you need. Could be a strange solution, but was helpful once.