Jump to content


Photo

*SOLVED*Fatal error: Maximum execution time of 30 seconds.!?!?! How do I get passed this?


  • Please log in to reply
14 replies to this topic

#1 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 28 April 2006 - 10:23 PM

I got this error while running a script that is going to make thumbnails of all 10,000 images on my server.

Fatal error: Maximum execution time of 30 seconds exceeded in /home/httpd/vhosts/bigornot.com/httpdocs/make_th.php on line 55

I don't care how long it takes to execute the script, so how can I get it to ignore this rule?

Thanks (need help ASAP)



#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 28 April 2006 - 10:36 PM

set_time_limit();
[a href=\"http://us2.php.net/function.set-time-limit\" target=\"_blank\"]http://us2.php.net/function.set-time-limit[/a]

be careful with that, though.

#3 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 28 April 2006 - 10:45 PM

Same error :( this time just on line 56 instead, because of the added line of code of course :P

Any other ideas?

ohh do I need to put a time between the brackets? I left them blank thinking that would give it an endless amount of time.

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 28 April 2006 - 10:48 PM

(per the manual link previously included) put a zero in the brackets for unlimited process time.

#5 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 29 April 2006 - 12:47 AM

Ok...problems.

Ok you were right.

You solved the timing out problem and I am not positive--because the file never totally loads--but I think the file crashes some where in the middle of the 2500 images in the first batch.

This is what I got now

<?
set_time_limit(0);

include("inc/db.inc"); 

$query = "SELECT photo2 FROM images";
$result = mysql_query($query);

while($info = mysql_fetch_array($result)){

gd2 image resize code

}
?>

How can I set this up so that it will pace its self?

hmmn maybe something like setting a limit and having a header at the end of the file that would redirect it to the same page but tell it where the limit left off?

Other ideas?

#6 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 29 April 2006 - 01:10 AM

Ok this is soooooo frustrating.

This is the code I have right now. It never loads to the next page. Just keeps trying to load the one page. GRRR

Please help, this is all I have left.


<?
set_time_limit(0);

include("inc/db.inc"); 

if(!($lastimage)){
    $lastimage = "0";
}

$query = "SELECT * FROM images ORDER BY id LIMIT $lastimage, 10";
$result = mysql_query($query);

while($info = mysql_fetch_array($result)){

    $imagename = $info['photo1'];

    // !!!! MAKE THUMNAIL !!!!
    $sourcefile = "images/" . $imagename;
    $forcedwidth = "75";
    $forcedheight = "75";
    $destfile = "images/th_" . $imagename;

    $fw = $forcedwidth;
    $fh = $forcedheight;
    $is = getimagesize( $sourcefile );
    if( $is[0] >= $is[1] )
    {
        $orientation = 0;
    }
    else
    {
        $orientation = 1;
        $fw = $forcedheight;
        $fh = $forcedwidth;
    }
    if ( $is[0] > $fw || $is[1] > $fh )
    {
        if( ( $is[0] - $fw ) >= ( $is[1] - $fh ) )
        {
            $iw = $fw;
            $ih = ( $fw / $is[0] ) * $is[1];
        }
        else
        {
            $ih = $fh;
            $iw = ( $ih / $is[1] ) * $is[0];
        }
        $t = 1;
    }
    else
    {
        $iw = $is[0];
        $ih = $is[1];
        $t = 2;
    }
    if ( $t == 1 )
    {
        $img_src = imagecreatefromjpeg( $sourcefile );
        $img_dst = imagecreatetruecolor( $iw, $ih );
        imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] );
        if( !imagejpeg( $img_dst, $destfile, 90 ) )
        {
            exit( );
        }
    }
    else if ( $t == 2 )
    {
        copy( $sourcefile, $destfile );
    }
    echo $destfile;
}
echo "done";
$newlast = "$lastimage + 10";
header("location: make_th.php?lastimage=$newlast");
?>



#7 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 29 April 2006 - 02:45 AM

okay strip the header redirect.

write a quick check in your loop that will autoadvance if it finds a thumb already. If there's a thumb, it skips it -- no thumb, it runs.

while($info = mysql_fetch_array($result)){

    $imagename = $info['photo1'];

    // !!!! MAKE THUMNAIL !!!!
    $sourcefile = "images/" . $imagename;
    $forcedwidth = "75";
    $forcedheight = "75";
    $destfile = "images/th_" . $imagename;
    if(!file_exists($destfile)) { // if the file doesn't exist -- do the following
        ... all your resize code here ...
    } // if the file exists, do nothing
} // end while loop

if it bombs, just run it again -- keeps bombing on the same image, you might just have a bad one.

another bit of advice... I'd use imagecreatefromstring(file_get_contents($sourcefile)) instead of imagecreatefromjpeg() to create your images. that way, if there just happens to be a PNG, GIF, or other image file in there, it gets read just fine.

#8 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 29 April 2006 - 03:19 PM

Good idea on the file exist, and I think your right with the imagecreatefromjpeg(). That might have been causing it to crash.

So you are saying get rid of the header redirect and the limits and all of that stuff and just let the script run with the above changes?

With these changes alone you think it is alright to let it rip on 4,000 images?

Thanks for the help.



#9 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 29 April 2006 - 04:42 PM

The header just loops the file into infinity. You can make the max execution time 0, but I'd probably do 240 or so. If it dies from execution time, just run it again.

#10 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 29 April 2006 - 05:02 PM

ohhhhhh, ok I see what you are saying now. It was almost too easy, I was trying to think too hard about it.

Ok just keep re running the script and everytime it will pass right by the ones I already did and start on new ones. So simple, your awesome, I'll try it out tonight and I don't see any reason why it woun'dt work. thanks.

-chris

#11 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 30 April 2006 - 02:05 AM

Michael I know you thought you had gotten rid of me, but not yet...sorry :(

Here it is... what I have no idea...

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 3072 bytes) in /home/httpd/vhosts/bigornot.com/httpdocs/make_th.php on line 57

-Chris

#12 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 30 April 2006 - 02:09 AM

Right next to that set_time_limit function (right above or below) add the following:

ini_set("memory_limit","128M");

that _should_ increase the image size suppored to 128mb... I've never gotten a memory error that the memory_limit increase to 128M didn't fix.

EDIT: ALSO -- if you might try imagedestroy() to destroy images once you've finished processing them -- before the loop starts over. destroy them all hahaha!

imagedestory($img_src);
imagedestory($img_dst);

that will free up any system resources (memory) taken up by those images before you try creating more.

#13 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 30 April 2006 - 02:24 AM

You are the best man, where do I send the beer to??

As for destroying the images, I want to keep the original image along with the new thumbnail. Does the image destroy delete the actual orignal image or just the memory space used for it?

-Chris


#14 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 30 April 2006 - 02:29 AM

it just deletes the GD object from memory. If these images are in the megabytes, then using the imagedestroy() function will just free up memory before trying to load more images into memory.

It's like unsetting the variable -- files on your hard drive aren't affected.

#15 cstegner

cstegner
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 30 April 2006 - 04:52 AM

Hey Michael, I just wanted to say thank you a million!

Everything is now working perfect! SOLVED!!!!

-Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users