MCrosbie Posted February 2, 2008 Share Posted February 2, 2008 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(); Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/ Share on other sites More sharing options...
resago Posted February 2, 2008 Share Posted February 2, 2008 try processing in stages. upload unzip resize you could use header redirects Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-455809 Share on other sites More sharing options...
budimir Posted February 2, 2008 Share Posted February 2, 2008 Try to check in your php.ini file the max_exec_time Change the value to 10000 or something like that. After that restart apache and try again! Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-456053 Share on other sites More sharing options...
MCrosbie Posted February 3, 2008 Author Share Posted February 3, 2008 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, Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-456633 Share on other sites More sharing options...
budimir Posted February 3, 2008 Share Posted February 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-456645 Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2008 Share Posted February 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-456782 Share on other sites More sharing options...
MCrosbie Posted February 4, 2008 Author Share Posted February 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-457206 Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2008 Share Posted February 4, 2008 You need to make sure that the php.ini that you are changing is the same one that php is using. Create a .php script file with the following code in it and browse to it, then scroll down or search for the actual runtime settings - <?php phpinfo(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-457210 Share on other sites More sharing options...
MCrosbie Posted February 4, 2008 Author Share Posted February 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-457221 Share on other sites More sharing options...
MCrosbie Posted February 5, 2008 Author Share Posted February 5, 2008 bumpety bump Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-458111 Share on other sites More sharing options...
resago Posted February 5, 2008 Share Posted February 5, 2008 what part is timeing out? uploading? unzipping? processing? Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-459217 Share on other sites More sharing options...
MCrosbie Posted February 6, 2008 Author Share Posted February 6, 2008 It's the processing of the images is where it's cutting out. The ZIP folder is uploaded fine, and the unzipping works fine, it's just the processing. Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-459277 Share on other sites More sharing options...
resago Posted February 6, 2008 Share Posted February 6, 2008 could you just cron it every 5 minutes? Quote Link to comment https://forums.phpfreaks.com/topic/88990-when-processig-large-files-timesout/#findComment-459316 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.