Unable to find the socket transport "http"

Hi,

When I’m running the bit of code below, I get this message:

Unable to find the socket transport “http” - did you forget to enable it when you configured PHP?)

I wouldn’t know how to troubleshoot this issue…


$str = '';
$sock = fsockopen('http://www.site.com/', 80);
$req =     "GET / HTTP/1.1\\r\
" .
        "Host: http://www.site.com/\\r\
" .
        "Connection: close\\r\
" .
        "\\r\
";

fwrite($sock, $req);
while ($buff = fread($sock, 1024))
    $str .= $sock;


Does anyone how to fix this?

Regards,

-jj. :slight_smile:

Ditch the occurances of http://

Thanks for your reply :slight_smile:

Did it, got that:

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Unknown Host.

The weird thing is that I can file_get_contents() the site I’m trying to connect to… I’m really lost…

:slight_smile:

Does this work?


fsockopen('www.google.com', 80);

yep.

Now if I do this:


$str = '';
$sock = fsockopen('www.google.com', 80);
$req =     "GET / HTTP/1.1\\r\
" .
        "Host: www.google.com\\r\
" .
        "Connection: close\\r\
" .
        "\\r\
";

fwrite($sock, $req);
while ($buff = fread($sock, 1024))
    $str .= $sock;

die($str);

I get:

Resource id #2

you want to echo $buff
The manual gives you a nice example of how to use fsockopen()