Nolongerused3921 Posted August 23, 2007 Share Posted August 23, 2007 For some odd reason, my script that worked on my previous server does not work on my new server - both are FreeBSD, both use the latest version of PHP... The only difference is, the new one is cPanel. Anyways, needless to say I'm completely stumped and am hoping someone here can help me figure out why my code has stopped working: $handle = fopen("http://www.filesite.com/file.jpg", "rb"); //Changed URL $file_contents = ''; while (!feof($handle)) { $file_contents .= fread($handle, 8192); } fclose($handle); $handle = ""; if (!$handle = fopen($filename, 'w')) { exit; } if (fwrite($handle, $file_contents) === FALSE) { exit; } fclose($handle); $Filename is defined above that, and that part works, as it saves the following to the file: <br /> <b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>/download.php</b> on line <b>51</b><br /> Line 51: $file_contents .= fread($handle, 8192); The file its trying to download is 334kB, so that may be part of it, seeing as a 18kB test file worked. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/ Share on other sites More sharing options...
Jessica Posted August 23, 2007 Share Posted August 23, 2007 You need to change the max execution time then. Use ini_set: http://us2.php.net/manual/en/function.ini-set.php http://us2.php.net/manual/en/ref.info.php#ini.max-execution-time Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332345 Share on other sites More sharing options...
Nolongerused3921 Posted August 23, 2007 Author Share Posted August 23, 2007 Thats an option, however theres a serious reason why my server (Which is dual core) won't download a 300kB file and I'd like to find out what it is, then fix it properly instead of hacking it. I just increased the length in fread to 65536 and it didn't change anything. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332351 Share on other sites More sharing options...
Jessica Posted August 23, 2007 Share Posted August 23, 2007 I'm no good with server issues. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332365 Share on other sites More sharing options...
lemmin Posted August 23, 2007 Share Posted August 23, 2007 It is the execution time, not the file size. Your server is allowing it to be downloaded, but your connection can't download it within 30 seconds. The only possible way to make your code work like that is to increas the max execution time. set_time_limit() is an easy function that will change it for only that instance. http://us.php.net/manual/fr/function.set-time-limit.php Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332366 Share on other sites More sharing options...
Nolongerused3921 Posted August 23, 2007 Author Share Posted August 23, 2007 Thats actually not the problem... It doesn't download to myself, only to the server- I have absolutely no interaction with the file - and besides, I download larger files through another script without any problems. And its definitely not a server download speed problem, since its downloading from a site hosted on the same server. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332373 Share on other sites More sharing options...
lemmin Posted August 23, 2007 Share Posted August 23, 2007 You said you download larger files without any problems (with another script,) so why do you think that it is the server not letting you download larger files, it clearly is, as you have stated. Since the error is "Maximum execution time of 30 seconds exceeded in..," it would seem like there is a loop that lasts longer than 30 seconds. There is only one loop in your code and that is reading the file. Just for troubleshooting sake, why don't you use: $file_contents = file_get_contents("http://www.filesite.com/file.jpg"); in place of all this: $handle = fopen("http://www.filesite.com/file.jpg", "rb"); //Changed URL $file_contents = ''; while (!feof($handle)) { $file_contents .= fread($handle, 8192); } fclose($handle); $handle = ""; It is a lot more efficient and that gets rid of the only endless loop would be possible. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332390 Share on other sites More sharing options...
Nolongerused3921 Posted August 23, 2007 Author Share Posted August 23, 2007 Tried that, same problem - however I just tried using the fopen and nothing else - and it takes more than 30 seconds... I believe the problem is here. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332408 Share on other sites More sharing options...
hitman6003 Posted August 23, 2007 Share Posted August 23, 2007 I download larger files through another script without any problems Do you download them from the same server? The connection from "www.filesite.com" may be slow to your server. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332412 Share on other sites More sharing options...
Nolongerused3921 Posted August 23, 2007 Author Share Posted August 23, 2007 Okay lets clear some stuff up... Download.php can do two things, it can either serve a user a file (This works fine, even with 2mB files) from the local directory, or it can download a file from the same script, on a different domain... Right now, ALL TESTING is done on a single server, but two different domains - lets call them site1, and site2. I'm currently trying to download a 333kB jpeg from site1 using the download.php script to both serve, and download the file (Serve from site1, download from site2). If I download the file directly, from my own computer, it works fine - even if its a large file. However, if I try to download the file from site2, it timesout. Now I highly doubt its because its not downloading fast enough, since it is downloading from the same server, the same IP, on the same network, etc.... Theres something wrong somewhere else, but I can't figure out where... To make matters worse, this worked before I moved to this new server. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332414 Share on other sites More sharing options...
lemmin Posted August 23, 2007 Share Posted August 23, 2007 If it is on the same machine, why don't you just do it locally? Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332421 Share on other sites More sharing options...
Nolongerused3921 Posted August 23, 2007 Author Share Posted August 23, 2007 If it is on the same machine, why don't you just do it locally? Because its two different accounts and I'd rather not open one up to the other. Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332422 Share on other sites More sharing options...
Nolongerused3921 Posted August 23, 2007 Author Share Posted August 23, 2007 I just had the dumb idea of testing some more files, and... Well, they all work - even 2mB+ ones. Anyone have ANY idea why this file wouldn't open a connection correctly? I even tried renaming it so it didn't have spaces, and it STILL doesn't want to fopen() it from site2. (Site1 is eyesoute.com) Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332446 Share on other sites More sharing options...
lemmin Posted August 23, 2007 Share Posted August 23, 2007 File permissions? Maybe the folder it was in has weird characters? Quote Link to comment https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/#findComment-332453 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.