Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/66404-file-downloading-not-working/
Share on other sites

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.

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

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.

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.

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.

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.