Forum Moderators: coopster
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?
If you're already doing that and still have a problem, I'd go with the cron job approach coopster suggested.