PDA

View Full Version : fsockopen problem



skip to my lou
29-07-2005, 02:27 AM
Does anyone here use PHP or C and fsockopen type function?




$blah = fsockopen( .... );
fclose($blah);

This, I think, closes the file pointer, but leaves the TCP connection in TIME_WAIT so if there are many requests, it could potentially fill up allocated memory tables and eventually crash the kernel.




for ($i = 0; $i < 1000; $i++)
{

$blah = @fsockopen ( .... );
// do something with $blah
@fclose($blah);

}


# netstat -n

And there are so many connections left in TIME_WAIT, some are in CLOSE. Is there any way to close these off immediately, either via the same PHP script, or a different Perl/Shell/C program?

I'm building a TCP port monitor to monitor about 8 services across 40 servers, so a few refreshes of the page, and that's already 1000's of connections left in TIME_WAIT.

Perhaps I should run the php script on cron, instead of opening new connections on each client request, but then it's not really real-time.

boardumb
30-07-2005, 11:17 PM
Not familiar with this fn, but usually the php docs are good...

http://au3.php.net/manual/en/function.fsockopen.php#51970

sounds similar to the problem that you're getting.

skip to my lou
31-07-2005, 01:46 PM
I've tried that, and unfortunately it does not work for me, however that seems like a very dodgy way to do it anyway.