dsaba Posted June 22, 2007 Share Posted June 22, 2007 Hello I am trying to test whether a proxy is working or not with cURL. cURL is a php libarary that gives you a set of functions/constants to be able to send custom headers to websites, POST to websites.etc.. And more importantly surf the site or grab its content under a proxy, instead of the server's own IP address. I have a list of proxies, and the problem is they don't all work, I want to test to see if they work with a curl function, that loads a google search page and then checks to see if it was loaded. The problem is this "test" works fine when a proxy does work, however when a proxy doesn't work the script lags, and ends up timing out trying to load the google page, because the proxy does not work. Therefore I want to to verify somehow if I can't load the page in so many seconds,(let's say 20 seconds) then it must mean that the proxy doesn't work. How can I check to see if the page doesn't load or if the script execution is in so many seconds while it executing itself? Is there some way I can access a live timer.. or some neat algorithim to check for this... ? This is my question/problem. Here is my function that uses cURL to check if a proxy works or not: <?php function curl_checkproxy($proxy) { $url = 'http://www.google.com/search?hl=en&safe=off&rls=TSHA%2CTSHA%3A2005-20%2CTSHA%3Aen&q=machiavelli'; $curlsource = curl_init(); curl_setopt($curlsource, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curlsource, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlsource, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($curlsource, CURLOPT_PROXY, $proxy); curl_setopt($curlsource, CURLOPT_URL, $url); $raw = curl_exec($curlsource); $findm = preg_match_all('/<title>(.*?)<\/title>/', $raw, $resultArray); $m =trim($resultArray[1][0]); if ($m == 'machiavelli - Google Search') { return TRUE; } else { return FALSE; } } ?> Again I somehow need to determine in how many seconds it tries to load the page, if its more than 20 I can just return FALSE.. How would this be possible?? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/56693-checkout-for-timeout-or-live-second-count-in-php-script-execution/ 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.