Jump to content

Custom timeout value


ionicle

Recommended Posts

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';
else
echo '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?

 

Link to comment
https://forums.phpfreaks.com/topic/280166-custom-timeout-value/
Share on other sites

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.

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

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.