Jump to content

Custom timeout value


ionicle
Go to solution Solved by AbraCadaver,

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

Edited by ionicle
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.