Code: Select all
<?php
if ($fileStream2 = fsockopen('www.example.com', 80, $errno, $errstr, 30))
{
//connection opened
echo '<p>Socket connection opened<br />';
//check out the filestream info
echo '$fileStream2 Info: ' . var_dump($fileStream2);
//get headers
$responseHeaders = get_headers('http://www.example.com/script.php');
//headers text
echo 'Response headers received<br>';
if (stripos($responseHeaders[0], '200 OK'))
{
//received good headers
echo 'Received 200 OK<br>';
//write the data to the file stream pointer
if (fwrite($fileStream2, $headers . $rsRequest))
{
echo 'Successfully wrote to the socket stream<br>';
}
//start reading contents
echo 'Reading contents received<br>';
while (!feof($fileStream2))
{
//err?
echo 'reading';
$contents .= fgets($fileStream2, 1024);
}
//what do we have?
echo 'Received contents: ' . $contents;
fclose($fileStream2);
} else
{
echo 'not writing';
$rsSent = false;
}
}Code: Select all
while (!feof($fileStream2))
{
//err?
echo 'reading';
$contents .= fgets($fileStream2, 1024);
}I can never get $contents because the page just continues in an infinite loop (and doesn't obey the 30 second timeout of my fsockopen() call).
I can't figure out why feof() is never returning true (I assume that is the problem). If i put exit; directly after the while (), it still goes into an infinite loop.
Can anyone help me out?
EDIT| This is the verbose output I am getting from my script:
Code: Select all
Socket connection opened
$fileStream2 Info: resource(12) of type (stream)
Response headers received
Received 200 OK
Successfully wrote to the socket stream
Reading contents received
(insert hang here :P)So.. hmmm it may be fgets()?