ソケット接続でオープン

/*
* ソケット接続でオープン
* /
class socketOpen{
public function __construct()
{
$host = "q.hatena.ne.jp";
$host = "yahoo.co.jp";
$path = "/";
$port = 80;
$fp = fsockopen($host, $port, $errno, $errstr, 10);
if (!$fp) {
echo "接続に失敗
";
echo "$errstr ($errno)
\n";
} else {
echo "接続に成功
";
$out = $this->request2($host,$port,$path);

fwrite($fp, $out);

while (!feof($fp)) {
echo fgets($fp, 1024)."
";
}
fclose($fp);
}



}

public function request($host,$port,$path)
{
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host \r\n";
$out .= "User-Agent: Mozilla/5.0\r\n";
$out .= "Connection: Close\r\n\r\n";
return $out;
}

public function request2($host,$port,$path)
{
$out = "GET $path HTTP/1.1\r\n";
$out .= "Referer: http://www.hogehoge.jp/\r\n";
$out .= "Host: $host \r\n";
$out .= "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n";
$out .= "Accept-Language: ja\r\n";
$out .= "Accept-Encoding: *\r\n";
$out .= "Accept-Charset: *\r\n";
$out .= "User-Agent: Fget by key\r\n";
$out .= "Connection: keep-alive\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "\r\n";
$out .= "\r\n";
return $out;
}
}