Hi all,

My webhoster is having some problems with the allow_url_fopen setting on
their servers. The problem occurs when try to include or fopen a external
file, which located on a slow or offline server. Because the allow_url_fopen
function uses blocking sockets PHP will wait until the external file is
opened, which can be quite a while if the external file is temporally
unavailable or the external server is too busy to handle the request for
this external file. This can result in problems on busy servers, too many
apache-child are kept open, doing nothing but waiting until the external
server responds.

This problem is causing so much problems, they want turn off the
allow_url_fopen setting, which is quite a hassle, because every user will
need to review all their scripts and possibly rewrite them.

I suggested they should patch their current version of PHP, so it will time
out after a specified number of seconds (which is quite easy because
php_hostconnect() already supports this). They are seriously considering
this and I've supplied them with the modifications to achieve this effect.
This is however not a long-term solution.

My question: to solve our problem it would be ideal to incorporate some sort
of setting which will tell the fopen wrapper to time out, or to use blocking
sockets. I've looked at the source of PHP and I think it would be quite easy
to implement

A new configuration setting should be introduced, which can be set in the
php.ini file.
The setting could be called 'url_fopen_timeout'.
This setting should be configured with the number of seconds before the
connection attempt will time out, or 0 if you don't want to let it time out.

The php_fopen_url_wrap_http() function located in
ext/standard/http_fopen_wrapper.c, would need just a little modification.

*socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0);

should be replaced by something like this:

if (cfg_get_double("url_fopen_timeout", &fopen_timeout) == SUCCESS) {
 *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM,
fopen_timeout);
} else {
 *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0);
}


Would somebody like to take a look at this and possibly include it in the
next release of PHP.
I would do it myself, but my C is a bit rusty (haven't used it since 1994).
So any help would be greatly appreciated.

Regards,

Niels Leenheer
[EMAIL PROTECTED]
--
phpAdsNew: http://sourceforge.net/projects/phpadsnew/



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to