我正在用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
我的结果是:
Connected to 1st server. VER 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 Connected to 2nd server. VER 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 Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\apps\msnphp\chat.php on line 54
连接到Nexus时出现超时错误。但是当我在Firefox中向https://nexus.passport.com/rdr/pprdr.asp发出请求时,我得到了我想要的结果(使用HttpFox检查)。为什么Nexus需要这么多才能回复我的剧本?在Firefox中需要2秒钟。
有谁知道我做错了什么?
答案 0 :(得分:5)
当您连接到nexus.passport.com上的SSL端口(443)时,您实际上并未发送加密信息:因此Nexus只是等待加密数据到达并最终超时(您的PHP脚本)在手前超时。
您可能最好使用Curl将信息发送给nexus,因为它能够为您处理SSL连接(为什么要重新发明轮子?)。
答案 1 :(得分:2)
您的脚本运行时间很长。 PHP有一种机制,如果它运行的时间比设置中指定的长,它会杀死脚本。您可以在max_execution_time
中更改此值(称为php.ini
),也可以使用set_time_limit()功能在脚本中更改它。