ionicle Posted July 15, 2013 Share Posted July 15, 2013 Hello, guys and girls! I need some help with the following snippet: <?php$ip = $_SERVER['REMOTE_ADDR'];$response = file_get_contents('http://www.shroomery.org/ythan/proxycheck.php?ip='.$ip);if ($response == 'Y')echo 'Proxy';elseecho 'Not Proxy';?> What it does, basically, is contact a proxy checker online, and based on whether the check returns a "Y" value, determines the outcome. What I want to add, is a sort of a custom timeout value, and when that runs out, no matter if a value has been obtained, the script should continue with the next instruction ( doing that to ensure that a temporary connection issue with the proxy checker will not impede the loading of the rest of the page ). How would I go about doing that? Quote Link to comment Share on other sites More sharing options...
ionicle Posted July 15, 2013 Author Share Posted July 15, 2013 (edited) Would that work: $arContext['http']['timeout'] = 3;$context = stream_context_create($arContext);$v_ip = $_SERVER['REMOTE_ADDR'];$response = file_get_contents('http://www.shroomery.org/ythan/proxycheck.php?ip='.$v_ip, 0, $context); if ($response == 'Y') { echo 'Proxy';die(); } I don't actually want to distinguish between the different kinds of errors a user might experience when contacting the proxy checker ( momentary failure at DNS resolution, unable to connect, slow connection etc. ), all I wanna do is ensure that, from the moment "file_get_contents('http://www.shroomery.org/ythan/proxycheck.php?ip='.$v_ip, 0, $context);" is executed, 3 seconds will elapse, and if no value of "Y" is returned, the script will just continue with the next instruction. Edited July 15, 2013 by ionicle Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 15, 2013 Share Posted July 15, 2013 Look at the HTTP class: http://us3.php.net/manual/en/book.http.php Options related to time outs timeout (integer) seconds the whole request may take to complete connecttimeout (integer) seconds the connect, including name resolving, may take dns_cache_timeout (integer) seconds after an dns cache entry times out Quote Link to comment Share on other sites More sharing options...
Solution AbraCadaver Posted July 15, 2013 Solution Share Posted July 15, 2013 Would that work: $arContext['http']['timeout'] = 3; $context = stream_context_create($arContext); That might work, I've never used it. Quote Link to comment Share on other sites More sharing options...
ionicle Posted July 16, 2013 Author Share Posted July 16, 2013 It did work indeed, like a charm. Thank you - consider the topic closed. 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.