Re: stream_set_timeout & get_headers (PHP5)

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

 



Chris wrote:
> I'm requesting some remote files to cache on my own server and performing
> a get_headers() first to find out the file type, since I don't always know
> what it is.  I've discovered some timeout problems with the remote server
> sometimes and my own script would end up with a fatal error because the
> script took longer to process than 30 seconds.  Being able to set a
> timeout would allow me to gracefully recover, rather than displaying an
> ugly error.
>
> I know I can use stream_set_timeout() on fsockopen() if I want to write my
> own get_headers function for < PHP5... but is it possible to set the
> timeout on PHP5's built in get_headers()?

I dunno the answer to your question, but...

It seems to me that you're just stressing your machine and theirs to do
two requests instead of one.

Go ahead and request the whole document, headers and all, and then start
reading the headers, and do whatever is right for your needs.

If you need to close the file once you find out the content-type, I
*believe* that will terminate the connection to the other server, and
avoid stressing it -- It will simply abort the sending of all the data you
don't need.

Chewing up another HTTP connection and another process is not a "win" in
performance, almost for sure.

You may also want to just change your timeout setting for this one script.
http://php.net/set_time_limit
Or, if you run this from a cron job or the command line, you can provide a
custom php.ini with: php -c /path/to/custom/php.ini filename.php

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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