Jump to content

When processig large files, timesout


MCrosbie

Recommended Posts

Hi,

 

I'm trying to make a photo gallery script where the admin can upload a ZIP file with photos inside.

 

Once uploaded it will be automatically unpacked, copied, resized for thumbnails, watermarked.

 

I've got Verot's upload class to do the processing, but the script always cuts out if the photos are larger, i.e. 1.9 MB etc. Below is my code for processing the files once they have been unzipped. It can handle processing files that are smaller than about 500KB but over that it tends to timeout.

 

			     $dirpath[0] = '../../../../media/DM_photogallery/'.$_GET['id'].'/';
			$dirpath[1] = '../../../../media/DM_photogallery/'.$_GET['id'].'/original/';
			$dirpath[2] = '../../../../media/DM_photogallery/'.$_GET['id'].'/watermarked/';
			$dirpath[3] = '../../../../media/DM_photogallery/'.$_GET['id'].'/thumbs/';
			$dirpath[4] = '../../../../media/DM_photogallery/'.$_GET['id'].'/ziptemp/';
	$picsdir=dir($dirpath[4]);
				$x = 1;
				while(($file = $picsdir->read()) !== false) {
					if($file != 'thumbs' and substr($file,0,1)!="."){
						if($file){
							$filename = $file;
							preg_replace('`[^a-z0-9-_.]`i','',$filename);
							$filename = str_replace(' ','_',$filename);
							$filename = str_replace(',','_',$filename);
							mysql_query("Insert into DM_photogalleryimg (gallery_id, file_name, title) values ('".$_GET['id']."','".$filename."','".$filename."')")or die("Error". mysql_error()."");
							copy($dirpath[4].''.$file,$dirpath[1].''.$filename);
							$handle = new Upload($dirpath[1].''.$filename);
							if ($handle->uploaded) {
								// save uploaded image with no changes
								$handle->image_resize = true;
								$handle->image_x = 150;
								$handle->image_y = 150;
								$handle->image_ratio = true;
								$handle->Process($dirpath[3]);
								if ($handle->processed) {
							  	} else {
									echo 'error : ' . $handle->error;	
								}
								$handle->image_watermark       = '../../../../media/watermark.png';
								$handle->image_resize = true;
								$handle->image_x = 650;
								$handle->image_y = 650;
								$handle->image_ratio = true;
								$handle->Process($dirpath[2]);
								if ($handle->processed) {
							  	} else {
									echo 'error : ' . $handle->error;	
								}

							}
							if($x == 1){
									$x = 0;
									sleep(4);
								}
								$x++;
							echo $filename.' Processed<br />';
							$processed_images = 1;
						}
					}
				}
				$picsdir->close();

Link to comment
Share on other sites

Hi,

 

Thanks both for your help.

 

Resago, I already tried doing this, but it still wasn't able to handle the larger files. Thanks for your suggestion though.

 

Budimir, I already have php.ini value for max_execution_time set to 10000. Is this different from max_exec_time?

 

Thanks again,

Link to comment
Share on other sites

I think the problem is with your php.ini settings.

 

Try setting max_execution_time = 1 000 000 000

                max_input_time = 6 000 000 000

                memory_limit = 800 M

               

I had the same problem and this solved it. Try it out. And you must restart Apache after making these changes, otherwise it doesn't matter.

 

Good luck

Link to comment
Share on other sites

While your problem might be time related, it is certainly size related.

 

Your upload code is probably not doing any error checking to see if the upload worked before blindly accessing the data. See this link for the errors that php can detect - http://www.php.net/manual/en/features.file-upload.errors.php

 

The default setting for upload_max_filesize is 2 Megabytes. If your code was doing some error checking, error reporting, and error recovery, it would tell you if you are exceeding the upload_max_filesize (the ['error'] element would have a value of 1.)

 

You need to change this setting to a value that is larger than you expect an uploaded file to be.

 

The next size limitation is post_max_size. The default value is 8 MB. If you expect to upload files greater than this, you must change it as well.

 

Stop and start your web server to get any changes made to php.ini to take effect.

 

All the above information is not a secret. There is a section in the php manual covering file uploads that lists the errors and states the common problems - http://www.php.net/manual/en/features.file-upload.php

Link to comment
Share on other sites

This is the php.ini file that I had originally:

 

; Maximum size of POST data that PHP will accept.
post_max_size = 50M

; Whether to allow HTTP file uploads.
file_uploads = On

; Maximum allowed size for uploaded files.
upload_max_filesize = 50M

; Maximuum execution time
max_execution_time = 500000

 

I will add budimir's suggestions and get back to you on how these went. Thanks PFMa for your help

 

 

Link to comment
Share on other sites

Yep they are changing and I've added budimirs suggestions and this still hasn't change the outcome.

 

This is my php.ini file now:

 ; Maximum size of POST data that PHP will accept.
post_max_size = 50M

; Whether to allow HTTP file uploads.
file_uploads = On

; Maximum allowed size for uploaded files.
upload_max_filesize = 50M

; Maximuum execution time
max_execution_time = 1000000000
                
; Maximum input time
max_input_time = 6000000000

; Memory limit
memory_limit = 800M

Link to comment
Share on other sites

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.