The issue was finally resolved when I began changing settings for server configuration, at prompting from responses to the StackOverflow question ( http://stackoverflow.com/questions/2617190/php-file-serving-script-unreliable-downloads )
Looking further into the filesize issue, I found that the size was being set correctly in the script, but that was not being reflected in the headers returned to the browser. Rather, the headers that were being returned were:
GET /download_video_test.php?t=KillsAids021&format=wmv HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:18.104.22.168) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
Cookie: style_cookie=printonly; phpbb3_7c544_u=2; phpbb3_7c544_k=44b832912e5f887d; phpbb3_7c544_sid=e8852df42e08cc1b2250300c2897f78f; __utma=174624884.2719561324781918700.1251850714.1270986325.1270989003.575; __utmz=174624884.1264524375.411.12.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=low%20stakes%20poker%20videos; phpbb3_cmviy_k=; phpbb3_cmviy_u=2; phpbb3_cmviy_sid=d8df5c0943863004ca40ef9c392d371d; __utmb=174624822.214.171.1240989003; __utmc=174624884
HTTP/1.1 200 OK
Date: Sun, 11 Apr 2010 12:58:02 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 mod_auth_passthrough/2.1 FrontPage/126.96.36.19935
Content-Disposition: attachment; filename=KillsAids021.wmv
Keep-Alive: timeout=10, max=30
In the end, it turned out that the problem was the gzip compression which was automatically being applied by my webserver for any php generated content. Below are the steps that I took to rectify it:
First, I established a new php.ini to control my individual folder on the shared server. Then I confirmed that my php.ini file was configured with
zlib.output_compression = Off That didn't solve it.
Next I looked at the specific settings for Apache. Since it's a shared server, I couldn't directly access any of the Apache configuration files, but I was able to control how I want my site handled, by creating a .htaccess file and adding the line:
SetEnvIfNoCase Request_URI \.php$ no-gzip dont-vary
With this line, none of my php will be compressed. That did the trick. The downside to this solution is that it will result in larger file sizes and bandwidth usage for the php pages on my site. A welcome upside is that it will reduce our CPU consumption (which is the only factor of being on a shared server that has been a limiting factor thus far). In the end, this is definitely a welcome change!