Question

I'm writing an MSN client in PHP. This is my code for so far:

$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

My result is this:

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

I get a timeout error when I connect to Nexus. But when I make a request to https://nexus.passport.com/rdr/pprdr.asp in Firefox, I get the result I want (checked with HttpFox). Why does Nexus take so much to to respond to my script? In Firefox it takes 2 seconds.

Does anyone know what I am doing wrong?

Was it helpful?

Solution

Whilst you are connecting to the SSL port (443) on nexus.passport.com , you aren't actually sending the information encrypted: therefore Nexus is just waiting for the encrypted data to arrive and eventually timing out (your PHP script is timing out before hand).

You'll probably be best using Curl to send the information to nexus as it's able to handle the SSL connection for you (why reinvent the wheel?).

OTHER TIPS

Your script is running to long. PHP has a mechanism where it kills a script if it runs longer then specified in settings. You can change this value (it's called max_execution_time) in your php.ini or you can use set_time_limit() function to alter it in your script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top