Jump to content

Limit time fsockopen() weird error.


Amired

Recommended Posts

Hi,

I'm trying to limit time for fsockopen(), so if it doesn't succeed in 2 seconds it will stop.

 

I have this:

 

 

	$fp = fsockopen('udp://'.$ip,$port,$errno,$errstr);
	$start = time();
	$allok = 1;

if($allok == 1)
{

	while(1) // infinite loop
	{
		if (time() > $start + '2')
		{
       			$allok = 0;
		return 1;
		}

	}

}
else
{
throw new Exception("function exceeded time");
}

 

But when I use it - all I get in the .php page is "Resource id #8" instead of what I need.

 

when I remove what I wrote and put just

 

$fp = fsockopen('udp://'.$ip,$port,$errno,$errstr);

 

Everything works fine.

what's the problem?

Link to comment
https://forums.phpfreaks.com/topic/146257-limit-time-fsockopen-weird-error/
Share on other sites

Why in the world are you adding '2' to a variable?  PHP just has to convert '2' to 2.

 

 

Anyway,

 

http://php.net/fsockopen

 

One of the parameters is how long to wait before timing out x.x.

 

 

Example:

 

$sock = fsockopen("google.com", 80, $errno, $errstr, 2);

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.