Page 1 of 2

some downloads freeze

Posted: Thu Mar 25, 2010 4:29 pm
by arcanus
Hello!

I am having trouble with my download function. I cannot reproduce the problem on any of my machines at home (WinXP, Mac OSX, Fedora11), but several people have written me and told me that whenever they try to download, it stops around 50%. Recently I've had people tell me that it stops at random places during the download. Reports have come in for Windows and Macs, Firefox, Internet Explorer, and Chrome. It doesn't seem specific to an operating system or browser. I have been able to reproduce this last issue on one of the Windows 7 machines on Firefox and Internet Explorer at my place of employment.

When I try to save the file, it will "complete" after a megabyte or less of data has been transferred.

When a user clicks on the "Download" link, it goes to a page called downloadShow.php. Here is my php code:

Code: Select all

<?php
$showName = $_GET['show'];
 
header("Content-type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-length: ".filesize($showName));
header("Content-disposition: attachment; filename=\"$showName\"");
readfile($showName);
 
?>
Someone suggested that perhaps there are only a certain number of threads my download function can handle and if I exceed that people are only able to download so much before getting cut off.

I really have no idea and I can't seem to find any useful information on the web and all of my other friends who know php far better than me haven't done anything like this.

When I started doing research on how to force a save dialog to come up, I saw many conflicting opinions on to do it and people blasting each other about using octet-stream or any other type. Unless there is no other choice (which I doubt), I do not want to have an html link and rely on the user to right-click save on their own. It's much nicer (IMO) to click on the link and bring up a dialog. My site. My design.

Can any please help me? This has been driving crazy for quite a while.

Thanks!
-tony

Re: some downloads freeze

Posted: Thu Mar 25, 2010 5:31 pm
by requinix
You were able to reproduce the problem? Consistently? How?


On another note, your script is horribly insecure. Anyone could download any file on your machine.
If you're interested in fixing this, explain what files the script is used for.

Re: some downloads freeze

Posted: Thu Mar 25, 2010 5:43 pm
by arcanus
I reproduced it be clicking on the "Download" link just like everyone else and saved it to my computer. When I'm on my machines at home, the downloads succeed and the files are complete. When I use the Windows 7 machine at work, clicking on the "Download" link and the file "successfully" downloads, but it's incomplete.

Fair enough about the security. Anyone could modify the URL to grab whatever they want if they know the directory and name. I'm totally open to suggestions. :)

The files being downloaded at mp3s. I have a podcast. People can use the flash player I have to listen directly, subscribe to the podcast, or click on a link to download the mp3 to their computer. I want a way to force the save dialog to appear as most people have Quicktime or some other program that will simply play the mp3 in the browser if they click on a link. I have a flash player for that.

Thanks!
-tony

Re: some downloads freeze

Posted: Thu Mar 25, 2010 5:58 pm
by requinix
Have you looked in error logs for any scripts ending prematurely?

How are the files arranged?

Re: some downloads freeze

Posted: Thu Mar 25, 2010 7:22 pm
by arcanus
I had not looked in my logs.

I tried downloading from a home machine and it finished after a few megabytes, which is wrong.

Access log:
{myIP} - - [25/Mar/2010:16:49:26 -0700] "GET /shows/downloadShow.php?show=XiledRadio-Show25.mp3 HTTP/1.1" 500 3956978 "http://www.xiledradio.com/shows.php" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 (.NET CLR 3.5.30729)"

I'm guessing the 500 refers the internal error and the 3956978 is the number of bytes downloaded. The correct size should be 82754563.

Error log:
[Thu Mar 25 16:49:34 2010] [error] [client {myIP}] File does not exist: /home/{myUsername}/xiledradio.com/internal_error.html, referer: http://www.xiledradio.com/shows.php

Not sure why it says the file does not exist, because it does.

The download link on the shows page is this:
<a href="/shows/downloadShow.php?show=XiledRadio-Show25.mp3">Download</a>

The shows page is located at the root level of the website.

There is a shows folder that contains all the mp3s and the downloadShows.php script.

Thanks!
-tony

Re: some downloads freeze

Posted: Thu Mar 25, 2010 9:06 pm
by s.dot
Your script is probably timing out
throw a set_time_limit(0); at the top of it

Re: some downloads freeze

Posted: Fri Mar 26, 2010 10:13 am
by arcanus
Hi s.dot.

set_time_limit(0);

did not solve the problem. Any other suggestions? :)

Thanks!
-tony

Re: some downloads freeze

Posted: Fri Mar 26, 2010 10:24 am
by Alkis
Try adding the following two headers on top of others:

header('Content-Description: File Transfer');
header('Content-Type: application/force-download ');

if does not work, try also removing the first one and/or the first two you have now (leaving the above two mention untouched).

let me know :)

Re: some downloads freeze

Posted: Fri Mar 26, 2010 10:38 am
by arcanus
Hi Alkis.

I tried adding the lines as you suggested. I removed the space between force-download and the apostrophe.

I did not work. I commented out my content-type and content-transfer-encoding lines too.

Thanks!
-tony

Re: some downloads freeze

Posted: Fri Mar 26, 2010 10:51 am
by Alkis
Right, that space on the force-download was a mistake.


Well...
try to also add the following lines to disable caching, in case there is any anywhere:

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sun, 01 Jan 2010 06:00:00 GMT");

Re: some downloads freeze

Posted: Fri Mar 26, 2010 11:10 am
by arcanus
No worries about the space. :)

Disabling cache also didn't solve my problem.

Appreciate all the suggestions!

Also, if there is an alternate way to allow someone to downloading a file in php, I'm willing to try that too. I tried a few other php methods (which I don't remember as that was months ago), but this was the only one I could get to actually download anything.

Thanks!
-tony

Re: some downloads freeze

Posted: Fri Mar 26, 2010 11:23 am
by Alkis
Maybe there is something on the server? Have you contacted the host company?

Are you trying to download the same file for test or not? If yes Maybe that file is corrupt in some way..

How exactly are the files being uploaded? through ftp or using a form? There are lots of posibilities/combinations that will may cause the download problem if it is not a server-side one.

try calling clearstatcache() function before your download-specific code.


Can't think of anything else at least right now. If I come up with anything I will let you know.

Re: some downloads freeze

Posted: Fri Mar 26, 2010 11:38 am
by arcanus
Hi Alkis.

I haven't tried to contact Dreamhost. I have tried downloading different files, all with the same result. I upload my files with sFTP via WinSCP. I know the files are not corrupt because I can listen to the mp3 files through my flash player and people are able to download the files and play them if they go to the podcast page and save from there. This is why I believe the problem has to do with my php script.

clearstatcache() didn't work for me either.

After typing my previous message, I went searching for other methods of downloading. I had tried fopen and fread in the past without success as I wasn't doing it right. Today's search led me here:

http://www.zubrag.com/scripts/download.php

I downloaded this file, modified the parts I needed to get it running, and it works! I'm now able to download files properly. The access.log doesn't show a 500 and is showing the correct values. There is no error in my error.log.

I'm still curious as to why my script worked in the past and now doesn't. Maybe zubrag's script won't work in the long run, but for now I'm happy to have something that seems to work. Now to test the hell out of it. :)

Thanks!
-tony

Re: some downloads freeze

Posted: Fri Mar 26, 2010 12:24 pm
by arcanus
I take it back.

The zubrag script doesn't work either. I'm just not seeing an error anymore. It will download a chunk of the mp3 and "succeed". The file is smaller than it should be and it'll play up to that point. :(

Re: some downloads freeze

Posted: Fri Mar 26, 2010 12:43 pm
by Alkis
I think you should make sure first that the problem isn't the host. Try contact them, explain the situation, and may there is a solution.