On Tue, Feb 14, 2012 at 1:28 PM, nik600 <nik...@gmail.com> wrote:
> Dear all
>
> i'm trying to handle a max timeout into a file_get_contents request,
> this is my code:
>
> ******* client.php ******* placed on http://test.foo.com/client.php
> <?php
> ini_set('default_socket_timeout',10);
> $ctx = stream_context_create(array('http' => array('timeout' => 10)));
> $data = file_get_contents("http://www.foo.com/server.php",0,$ctx);
> if(!data){
> die("error during page request");
> }else{
> echo "OK";
> echo $data;
> }
> ?>
>
> ******* server.php ******* placed on www.foo.com at
> http://www.foo.com/server.php
> <?php
> sleep(15);
> echo "OK";
> ?>
>
> i've noticed that in a standard scenario if i call
> http://test.foo.com/client.php all works properly and the timeout is
> handled correctly.
>
> But, if i'm experiencing dns lookup problems, the timeout setting is
> ignored by file_get_contents, or more probably the socket isn't yet
> estabilished so the counter for timeout doesn't start.
>
> I've been able to reproduce this problem on a linux server dropping
> incoming packets of DNS with this command: (be careful, it will
> disable you ability to resolve all dns address!):
>
>    * iptables -A INPUT -p udp --sport 53 -j DROP
>    * iptables -A INPUT -p tcp --sport 53 -j DROP
>
> So, the question is:
>
> is possible to have a timeout check that includes also dns resolution time?
>
> Thanks to all in advance

I don't think this is possible with file_get_contents, but it should
work if you use cURL and set the CURLOPT_CONNECTTIMEOUT option.

- Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to