Jump to content

a time out?


Michdd

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/154798-a-time-out/#findComment-814121
Share on other sites

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
}
   
;?>

 

Link to comment
https://forums.phpfreaks.com/topic/154798-a-time-out/#findComment-814223
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.