Edit report at https://bugs.php.net/bug.php?id=36072&edit=1

 ID:                 36072
 Comment by:         colin at mollenhour dot com
 Reported by:        ceo at l-i-e dot com
 Summary:            stream_set_connection_timeout()
 Status:             Open
 Type:               Feature/Change Request
 Package:            Streams related
 Operating System:   *
 PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

I think an excellent solution would be to add a "timeout" option to the Socket 
stream options. The HTTP stream already supports timeout, but not regular 
sockets.  
For example, I want to connect to a Redis server using tcp for caching 
(infinite 
timeout needed for blocking calls) and may want to connect to a different 
server 
for some other purpose with a short timeout. Example:

$context = stream_context_create(array('socket' => array('timeout' => 5)));


Previous Comments:
------------------------------------------------------------------------
[2010-09-27 16:13:26] cataphr...@php.net

You can already do this for http/https:

<?php
$context = stream_context_create(
        array(
                "http" => array("timeout"=>2),
));
var_dump(fopen("http://136.234.1.4/";, "r", false, $context));

For FTP, there isn't unfortunately a way, by you can set a default timeout:

ini_set("default_socket_timeout", 2);

------------------------------------------------------------------------
[2006-01-19 00:31:14] ceo at l-i-e dot com

Errrr. If you read the actual Feature Request, I think it's pretty clear that 
RTFM stream_set_timeout won't cut it...

stream_set_timeout is useful only AFTER a stream is open.

fopen() gives no control (tho fsockopen() does) over connection timeout.

But fsockopen is missing all the great stuff in fopen() that takes care of.

I really don't think I'm being an idiot here...  Honest.

------------------------------------------------------------------------
[2006-01-18 21:24:49] he...@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

RTFM: stream_set_timeout(), context of fopen(), streams section in manual

------------------------------------------------------------------------
[2006-01-18 21:16:55] ceo at l-i-e dot com

Description:
------------
I love the simplicity of fopen() that takes most URLs / files / whatever and 
does what I want.

Do whatever it takes to start sending me the data.

I NEED the ability to set the time-out for the opening, as well as the time-out 
after the stream has opened.

I'm stuck with duplicating whatever code is down in fopen() in my own PHP code 
to detect and initiate protocol specific minutia because fopen() has no 
user-configurable timeout, but fsockopen doesn't do all that.
$parts = parse_url($url);
extract($parts);
switch($scheme){
case 'http': fputs("GET $path HTTP/1.0\n"); fputs("Host: $host\n"); break;
case 'ftp': fputs("GET $path\n"); break;
.
.
.
}

I REALLY don't want to re-invent the wheel here, when I know that code is down 
in the guts of fopen()

A function stream_set_connection_timeout() to let me tell PHP how long fopen() 
should wait would make life way more better for many users, I believe.


Expected result:
----------------
The PHP Dev Team is going to add this function because YOU ROCK!
:-)




------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=36072&edit=1

Reply via email to