Jump to content

checkout for timeout or live second count, in php script execution


Recommended Posts

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.