Fatal error: maximum execution time exceeded when generating mass thumbnails in php

I am trying to write a PHP script that will perform the following:

  1. Extract all files from an archive in a given directory (using the exec function to actually run 7z)

  2. List all the files that are images (jpg, jpeg, gif, png) and store them in an array (using exec again to run "ls" and storing only the images in the array, I compare the extension)

  3. Cycle through the array and for each image:
    1. Move that image in a unique folder
    2. Generate thumbnails in that same unique folder (I use PHP Thumbnailer)
    3. Record that new image in a database

For a small number of images, I would say that the script works ok (it could probably be improved a lot).

My problem is that after a certain number (which seems random each time I run my script) of treated images, I get a fatal error: PHP Fatal error: Maximum execution time of 60 seconds exceeded in /var/www/ims/public_html/dev/include/phpThumb/GdThumb.inc.php on line 217

imagecopyresampled
(
    $this->workingImage,
    $this->oldImage,
    0,
    0,
    0,
    0,
    $this->newDimensions['newWidth'],
    $this->newDimensions['newHeight'],
    $this->currentDimensions['width'],
    $this->currentDimensions['height']
); // <- this is line 217

I am hoping that someone could point me towards a reason for that timeout. Is the GD library limited ? Should I install a dedicated software on my linux server to specifically perform this task?

Thanks for your help.

Answers


The 60 second time limit is for the entire scripted process. It is primarily intended to keep a rogue php child process from tying up the apache child (or other web server resource) on a loaded server.

If you are using php as a shell scripting language rather than as a web application I would recommend either set_time_limit(0); or making sure you are running the script in the php cli interpreter which does this automatically.

If you are trying to perform a large batch operation in response to a document upload/form post within a web server, you might want to look into using some sort of job server to offload the processing work to instead of keeping the web server tied up for a long period of time. Gearman is one such system.


Need Your Help

what is causing my double-submit issue? (been 3 days now with 0 progress)

jsp spring-mvc tiles

I'm getting a double-submit issue, and after 3 days, have still been able to determine the cause.

Line Continuation Spring SQL ScriptUtils (Using H2)

java sql spring jdbc h2

I have the following SQL script (initDB.sql)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.