Why does file_get_contents take twice the time of default_socket_tieout when timeout occurs?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I use file_get_contents to access to a web api.
It's timeout is set by default_socket_timeout.
When a web api took a long time to response, of course file_get_contents timed out.
But It seemed strange. file_get_contents took more time than default_socket_timeout.

For reproducing this problem,
I prepared the program that took enough time to cause timeout and I tested file_get_contents.
As a result, I found that file_get_contents takes twice the time of default_socket_tieout when timeout occurs.
For example, when I set default_socket_timeout to 3 sec, file_get_contents takes 6 seconds to return the result.

Why does file_get_contents take twice the time of default_socket_tieout when timeout occurs?

######
# code #
######

--------------------------------------------------
<?php
ini_set('default_socket_timeout', 3);
echo file_get_contents('http://foo.bar.jp/sleep');
--------------------------------------------------

# If I use curl module, this problem doesn't occur.
--------------------------------------------------
<?php
$ch = curl_init('http://foo.bar.jp/sleep');
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_exec($ch);
curl_close($ch);
--------------------------------------------------

##########
# php version #
##########

$ php --version
PHP 5.4.6 (cli) (built: Jun 19 2014 17:43:25)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies


------

Masahiro Honma



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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux