Re: Slow file download

From: Date: Tue, 02 Dec 2008 20:58:37 +0000
Subject: Re: Slow file download
Groups: php.general 
Request: Send a blank email to php-general+get-284009@lists.php.net to get a copy of this message
If the files are LARGE, file_get_contents is a Bad Idea (tm). You're trying to suck the whole thing into RAM, which it can't, which swaps and thrashes the bleep out of your RAM/swap space... Use fopen and an fread loop instead, and you'll probably see much better performance. Also, consider going old school and getting rid of the stream_context stuff. It's "new" and "untested" :-) You can use ini_set and the parameter or even fall back to fsockopen with a timeout. Note that those time-outs are for any given packet to arrive (or the socket to open) not the whole enchilada to download.

« previous php.general (#284009) next »