Michdd Posted April 19, 2009 Share Posted April 19, 2009 Using a mysql connection and something like.. if(!$connection) works to determine of the server is offline, but that takes a long time (around 10 seconds) is there a way to make it stop trying after say 2 seconds? Quote Link to comment Share on other sites More sharing options...
alphanumetrix Posted April 19, 2009 Share Posted April 19, 2009 Yeah, try using set_time_limit(2); Quote Link to comment Share on other sites More sharing options...
Michdd Posted April 19, 2009 Author Share Posted April 19, 2009 That won't work, because I need it to do something else, not return an error. I was thinking about something like this: <?php $start = time(); function online($connection) { while(!$connection) { if(time() - $start >= 2) { return false; break; } } return true; } if(online($connection)) { //Your server is online.. } else { //It's not } But it still takes the same amount of time. Quote Link to comment Share on other sites More sharing options...
alphanumetrix Posted April 20, 2009 Share Posted April 20, 2009 well, that code wouldn't work anyway. you declared $start outside of the function without making it global: $start = time(); function online($connection) { global $start; put this code at the top of your script: <?php $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; ;?> then put this where you want it: <?php $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); function online($connection) { global $totaltime; while(!$connection) { if($totaltime >= 2) { return false; break; } } return true; } if(online($connection)) { //Your server is online.. } else { //It's not } ;?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.