Amired Posted February 21, 2009 Share Posted February 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/146257-limit-time-fsockopen-weird-error/ Share on other sites More sharing options...
corbin Posted February 21, 2009 Share Posted February 21, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/146257-limit-time-fsockopen-weird-error/#findComment-767858 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.