note 64011 added to function.fopen

From: Date: Wed, 05 Apr 2006 14:02:39 +0000
Subject: note 64011 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-107384@lists.php.net to get a copy of this message
During development of a set of non-blocking functions for downloading files from http-servers I've discovered that it's not possible to set timeout for fopen('http://somesite.com/somefile', 'rb'). All functions for controlling non-blocking mode (stream_set_blocking, stream_set_timeout, stream_context_set_option) use resource handle that is created via fopen(). But fopen() for HTTP connections internally makes quite a big set of actions: it creates socket, resolves webserver name, establishes actual connection. So hanging can occur anywhere in resolving and creating tcp-connection but you cannot control it. Solutions: 1) Use socket functions. Set socket in non-blocking mode just after creation. Implement HTTP-protocol yourself. In source code use these manually created functions. 2) Write a wrapper for myprotocol://, which internally will use first solution, but in source code you'll use fopen('myprotocol://somesite.com/somefile', 'rb') with some way to set timeout before calling it. ---- Server IP: 66.163.161.117 Probable Submitter: 213.133.165.251 (proxied: 192.168.0.37) ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- http://master.php.net/note/edit/64011 Del: integrated -- http://master.php.net/note/delete/64011/integrated Del: useless -- http://master.php.net/note/delete/64011/useless Del: bad code -- http://master.php.net/note/delete/64011/bad+code Del: spam -- http://master.php.net/note/delete/64011/spam Del: non-english -- http://master.php.net/note/delete/64011/non-english Del: in docs -- http://master.php.net/note/delete/64011/in+docs Del: other reasons-- http://master.php.net/note/delete/64011 Reject -- http://master.php.net/note/reject/64011 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107384) next »