bjmosk Posted February 2, 2009 Share Posted February 2, 2009 Hello, I have a PHP script that loops through a potentially large number of JPG images - it must read the width and height, and rotate each one by 90 degrees. There may be a couple thousand images in this loop, and each image is a photo of good quality, 3+ MB in size. All the PHP timeout and memory use settings have been adjusted properly to accommodate this script. However, it does hang quite frequently and I'm thinking it may be due to the memory required for such a task. I'm trying my best to clean up all my variables and objects on each iteration, but it doesn't seem to free all the memory it should. I've checked memory_get_usage() etc. which seems to confirm this (although I think I remember reading somewhere that the value may be unreliable). I'm thinking of writing a separate PHP script to handle the image rotation. On each iteration of the above loop I'd kick off this script via exec(). It would rotate the photo and then end. These are my questions: 1) Is this considered a safe solution? I try to avoid using exec() if I can. 2) Is the solution unnecessary? Should one PHP script be able to handle such a loop without a problem? Any help would be greatly appreciated. Thanks, Brian Quote Link to comment https://forums.phpfreaks.com/topic/143424-rotating-large-number-of-photos-in-one-script/ Share on other sites More sharing options...
uniflare Posted February 2, 2009 Share Posted February 2, 2009 I dont dabble in this myself, but i had a little look for you and should be interesting for you; http://theserverpages.com/php/manual/en/function.imagerotate.php http://uk3.php.net/imagerotate The comments on that page give lots of personal examples (i only scanned so i dont know the quality of the code). But it should give you some ideas, this is a quote: If you need a rotate function, ask your provider to install JPEGTRAN on the machine your server runs on and use the command line tool from your php application. JPEGTRAN is a *nix command, more information: http://linux.about.com/library/cmd/blcmdl1_jpegtran.htm Quote Link to comment https://forums.phpfreaks.com/topic/143424-rotating-large-number-of-photos-in-one-script/#findComment-752308 Share on other sites More sharing options...
MadTechie Posted February 2, 2009 Share Posted February 2, 2009 are you sure its not a timeout problem (dues it fail after 30,60 , 90 seconds ?) what about a script that resizes an image then uses a HTML Meta tag to redirect to the same page with a parameter that points to the next file ie rotatimg.php?ID=1 rotatimg.php?ID=2 rotatimg.php?ID=3 rotatimg.php?ID=4 ... this should clear the memory used and also stop any timeout issules Quote Link to comment https://forums.phpfreaks.com/topic/143424-rotating-large-number-of-photos-in-one-script/#findComment-752497 Share on other sites More sharing options...
bjmosk Posted February 2, 2009 Author Share Posted February 2, 2009 MadTechie - thanks. I know it's not a problem with the script timing out, but the meta tag redirect is along the lines of what I was thinking. I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/143424-rotating-large-number-of-photos-in-one-script/#findComment-752686 Share on other sites More sharing options...
uniflare Posted February 2, 2009 Share Posted February 2, 2009 i would recommend header redirects . they seem to work more efficiently to me - unless ou want to display a message each time . Quote Link to comment https://forums.phpfreaks.com/topic/143424-rotating-large-number-of-photos-in-one-script/#findComment-752890 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.