我正在用 PHP 编写一个 MSN 客户端。这是我到目前为止的代码:
$socket = fsockopen("messenger.hotmail.com", 1863);
echo '<b>Connected to 1st server.</b><br />';
//Send MSNP version
fputs($socket, "VER 0 MSNP10 CVR0\r\n");
echo fread($socket, 5000) . '<br />';
//Send user-agent
fputs($socket, "CVR 1 0x0409 php ".phpversion()." i386 MSNMSGR 7.0.0000 MSMSGS ".$_POST["username"]."\r\n");
echo fread($socket, 5000) . '<br />';
//Send username
fputs($socket, "USR 2 TWN I ".$_POST["username"]."\r\n");
//Read XFR
$xfr = fread($socket, 5000);
echo $xfr . '<br />';
$xfr = explode(" ", $xfr);
//Connect to second server
$server2 = explode(":", $xfr[3]);
$socket = fsockopen($server2[0], (int)$server2[1]);
echo '<b>Connected to 2nd server.</b><br />';
//Send MSNP version
fputs($socket, "VER 0 MSNP10 CVR0\r\n");
echo fread($socket, 5000) . '<br />';
//Send user-agent
fputs($socket, "CVR 1 0x0409 php ".phpversion()." i386 MSNMSGR 7.0.0000 MSMSGS ".$_POST["username"]."\r\n");
echo fread($socket, 5000) . '<br />';
//Send username
fputs($socket, "USR 2 TWN I ".$_POST["username"]."\r\n");
//Read USR
$usr = fread($socket, 5000);
echo $usr . '<br />';
$usr = explode(" ", $usr);
//Connect to Nexus
$nexus = fsockopen("nexus.passport.com", 443);
$request_nexus = "GET /rdr/pprdr.asp HTTP/1.1\r\n";
$request_nexus .= "Host:nexus.passport.com\r\n";
$request_nexus .= "User-Agent:MSNphp/1.0 (PHP; U; PHP 5; en-US)\r\n";
$request_nexus .= "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$request_nexus .= "Accept-Language:en-us,en;q=0.5\r\n";
$request_nexus .= "Keep-Alive:300\r\n";
$request_nexus .= "Connection:keep-alive\r\n";
$request_nexus .= "Cache-Control:max-age=0\r\n\r\n";
fputs($nexus, $request_nexus);
echo fread($nexus, 5000);//This is line 54, which causes the error
我的结果是这样的:
连接到第一台服务器。 版本 0 MSNP10 CVR 1 1.0.0000 1.0.0000 1.0.0000 http://msgr.dlservice.microsoft.com http://download.live.com/?sku=messenger XFR 2 NS 207.46.124.241:1863 0 65.54.239.21:1863 连接到第二台服务器。 版本 0 MSNP10 CVR 1 1.0.0000 1.0.0000 1.0.0000 http://msgr.dlservice.microsoft.com http://download.live.com/?sku=messenger USR 2 TWN S ct=1249043921,rver=5.5.4177.0,wp=FS_40SEC_0_COMPACT,lc=1033,id=507,ru=http:%2F%2Fmessenger.msn.com,tw=0,kpp=1,kv=4 ,ver=2.1.6000.1,rn=1lgjBfIL,tpf=b0735e3a873dfb5e75054465196398e0 致命错误:第 54 行的 C:\wamp\apps\msnphp\chat.php 中超过了 30 秒的最大执行时间
连接到 Nexus 时出现超时错误。但是当我在 Firefox 中向https://nexus.passport.com/rdr/pprdr.asp发出请求时,我得到了我想要的结果(用 HttpFox 检查)。为什么 Nexus 需要花这么多时间来响应我的脚本?在 Firefox 中需要 2 秒。
有谁知道我做错了什么?