I wrote this function to get the unread count of google reader items.
function GetUnread($sid)
{
$url = "http://www.google.com/reader/api/0/unread-count?all=true&output=xml";
$msg = urldecode($msg);
$msg = stripslashes($msg);
$msg = urlencode($msg);
$url = $url . $msg;
$purl = parse_url($url);
$uri = $purl['scheme'] . "://" . $purl['host'] . $purl['path'] . "?" . $purl['query'];
$cookie = "Name=SID;SID=" . $sid . ";Domain=.google.com;Path=/;Expires=16000000";
$headers = array();
array_push($headers, "GET " . $uri . " HTTP/1.0");
array_push($headers, "Host: " . $purl['host']);
array_push($headers, "Referer: " . $uri);
array_push($headers, "Cookie: " . $cookie);
array_push($headers, "");
$headers = implode("\r\n", $headers);
echo $headers;
$conn = fsockopen($purl['host'], 80, $errno, $errstr, 30);
if ($conn)
{
fputs($conn, $headers);
$response = "";
while (!feof($conn)) //Appears to loop indefinitely until feof's timeout(60)
{
$response .= fgets($conn, 128);
}
fclose($conn);
}
echo $response;
}
The headers when produced look like this:
GET http://www.google.com/reader/api/0/unread-count?all=true&output=xml HTTP/1.0
Host: www.google.com
Referer: http://www.google.com/reader/api/0/unread-count?all=true&output=xml
Cookie: Name=SID;SID=DQA...zA;Domain=.google.com;Path=/;Expires=16000000
It just sits there and once finished loading there is no response string. Is it an issue with the headers or the fsockopen?
Firstly try simplifying the url you're trying to get (just try google.com). If that returns a response there's a chance there could be some sort of authentication issue.