fsockopen

Ask questions about dedicated servers here and we and other users will do our best to answer them. Please also refer to the self-help section for tutorials and answers to the most commonly asked questions.
Post Reply
Dooty
A semi-regular
A semi-regular
Posts: 24
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Tue Mar 26, 2013 11:10 am

fsockopen

Post by Dooty »

$fp = @fsockopen($serverip, $loginport, $errno, $errstr, 1);
if (!$fp)
{ echo $offline; } else { echo $online; }
@fclose($fp);

does that open a database connection?
User avatar
Vanderburg
Former staff
Former staff
Posts: 1253
Joined: Sat Nov 13, 2010 7:27 am
Location: Dallas, TX

Re: fsockopen

Post by Vanderburg »

That simply tests to see if a connection can be made (And suppresses any error that might be generated in the process). If you're doing it procedurally, you will want to look up mysql_connect(), or if using objects, mysqli().
Dooty
A semi-regular
A semi-regular
Posts: 24
Joined: Tue Mar 26, 2013 11:10 am

Re: fsockopen

Post by Dooty »

so if that is sent enough times, it can cause mysql to have too many connections?
User avatar
Vanderburg
Former staff
Former staff
Posts: 1253
Joined: Sat Nov 13, 2010 7:27 am
Location: Dallas, TX

Re: fsockopen

Post by Vanderburg »

If you don't close the connection fast enough, yes, but the scripts are usually run so quickly that it takes these being run in quite close succession to be able to hit that number.
Dooty
A semi-regular
A semi-regular
Posts: 24
Joined: Tue Mar 26, 2013 11:10 am

Re: fsockopen

Post by Dooty »

so for the code i posted. does it even close the connection? cause after i removed it, my server no longer gets too many connections
User avatar
Vanderburg
Former staff
Former staff
Posts: 1253
Joined: Sat Nov 13, 2010 7:27 am
Location: Dallas, TX

Re: fsockopen

Post by Vanderburg »

Yes, fclose() closes that connection, but if I understand correct, you have an it would actually open two connections, one for the script and the script opening one with fsockopen.
Post Reply