casualcoder Posted March 13, 2013 Share Posted March 13, 2013 I've been having trouble with one of my download scripts i've been using for a while which prevents users from seeing the direct-link location of a file. It's a simple php script which has worked on and off on several servers in the past. I used to think that it "stopped" working because of an issue with my hosting account but now it's happening too often that I have to consider the script is doing something wrong and clogging something up on the server. So, first the script itself (relevent parts only, disregard syntax or undefined variables, assume its all there): <?PHP$file_name = "download.zip";$filelocation = "$rowx[FILE_URL]"; //fetches the file url from mysql database. header("Content-type: application/octet-stream\n"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0\n"); header("Content-Transfer-Encoding: binary\n"); header("Content-disposition: attachment; filename=\"$file_name\"\n"); readfile("$filelocation");?> Simple, right? One thing the script never does is actually find the filesize and allow for a perctage download indicator. The download is always for an "unknown" size. This could be part of the problem. Also, I checked to make sure there was no mysql database issue (being open too long or whatnot) so i closed the connection at the end of the script. Problem persists. My host advised me to increase the memory limits and cache in the php.ini file. It did absolutely nothing. Recently, when the problem came back on a new server. The host told me to upgrade to a dedicated IP, which I went ahead and did.The problem DID go away around this time, but I can't attribute it to the dedicated IP because they (the host) were likley mucking around the server around the same time and could have been flushing cache's and any number of things so I can't say what fixed it temporarily. My suspicion is still that something in the script is causing a table on the server to fill up and perhaps its not being dumped as new data is being written, hence the terminated download. That's only a guess, however. I've been having this problem on and off for YEARS, so a big thanks in advance to anyone who can help even a little. Quote Link to comment https://forums.phpfreaks.com/topic/275630-download-script-timing-out/ Share on other sites More sharing options...
kicken Posted March 14, 2013 Share Posted March 14, 2013 Is $filelocation a local file, or a remote URL? Based on the naming, I am guessing the latter. Can you be more descriptive of how exactly the script fails? Does it end the download prematurely? Are there any PHP error messages if you look at the downloaded file in a text editor? Does the download not start at all? Also you shouldn't have the \n at the end of your header() lines. Try increasing the timeout using set_time_limit Quote Link to comment https://forums.phpfreaks.com/topic/275630-download-script-timing-out/#findComment-1418524 Share on other sites More sharing options...
casualcoder Posted March 16, 2013 Author Share Posted March 16, 2013 Thanks for your reply. $filelocation refers to a local file hosted under the public_html directory in several subfolders. The script fails by randomly terminating before it completes. For example, a 300mb file may terminate anywhere between, say, 25mb downloaded or 200mb downloaded as a general rule. There are no error messages during execution of the script or upon termination. It just looks to the end user like the file downloaded fully and successfuly. I tried changing the set_time_limit() option before (it was one of the early suggestions made by my host) however it made no difference. Quote Link to comment https://forums.phpfreaks.com/topic/275630-download-script-timing-out/#findComment-1418952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.