prodigy2k7 Posted September 9, 2007 Share Posted September 9, 2007 Hello, I am a novice PHP scripter. I mostly create small things or adjust php scripts i find online slightly and use them. This time I am having a problem. This script takes images in a directory, makes thumbnails of the images 1 by 1 in it and puts it in "thumbs" directory. It works fine, but if I have a lot of images, once it gets to about 30 seconds in... it just stops, with no errors, the browser says "Done" (firefox). set_time_limit(0); function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) { $dir = opendir( $pathToImages ); while (false !== ($fname = readdir( $dir ))) { $info = pathinfo($pathToImages . $fname); if ( strtolower($info['extension']) == 'jpg' ) { echo "Creating thumbnail for {$fname} <br>"; $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" ); $width = imagesx( $img ); $height = imagesy( $img ); $new_width = $thumbWidth; $new_height = floor( $height * ( $thumbWidth / $width ) ); $tmp_img = imagecreatetruecolor( $new_width, $new_height ); imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" ); } } echo "done1"; closedir( $dir ); echo "done2"; } I tried for fun the two "echo"s at the end, it never reaches that. I also tried "set_time_limit(0);" at the top, I dont know if I used that correctly, but ya.. Anyone have any ideas? Thanks, Kenny Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/ Share on other sites More sharing options...
prodigy2k7 Posted September 10, 2007 Author Share Posted September 10, 2007 Bump Edit: I will give $10 via paypal for whoever to fix this problem. I need it fixed fast! No responses yet! Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/#findComment-345032 Share on other sites More sharing options...
prodigy2k7 Posted September 10, 2007 Author Share Posted September 10, 2007 Bump! I tried adding into the code after imagejpg imagedestroy($tmp_img); imagedestroy($img); It seems this would be my problem, yet it still stops! I dont know what to do. Once again! $10 through paypal to anyone to helps me and fixes it. Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/#findComment-345077 Share on other sites More sharing options...
Fadion Posted September 10, 2007 Share Posted September 10, 2007 Actually max_execution_time is 30, which means your script will be stopped after 30 seconds. In the beginning of the script: <?php ini_set('max_execution_time', '180'); ?> From the manual: You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/#findComment-345126 Share on other sites More sharing options...
Fadion Posted September 10, 2007 Share Posted September 10, 2007 If that fixes the problem i want my 10$!! LOOL jk m8. Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/#findComment-345128 Share on other sites More sharing options...
btherl Posted September 10, 2007 Share Posted September 10, 2007 Here's one solution: set_time_limit(0); ob_implicit_flush(); for ($i = 0; $i < 100; $i++) { print "$i seconds<br>"; sleep(1); } Try that out .. if it works, you can similarly print out messages to avoid browser timeout. Keep in mind that it's not very efficient to send individual messages like this (it takes more network bandwith this way). It may not work if you have mod_gzip active. Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/#findComment-345145 Share on other sites More sharing options...
prodigy2k7 Posted September 10, 2007 Author Share Posted September 10, 2007 Actually, for kicks i modified my php.ini to change the max, still didnt work... I dont even know what that does, does that go in or outside of my while loop? Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/#findComment-345159 Share on other sites More sharing options...
btherl Posted September 10, 2007 Share Posted September 10, 2007 Hmm, my suggestion was for avoiding browser timeout. It's difficult to tell which problem you have, browser timeout or server timeout. Which browser are you using? Quote Link to comment https://forums.phpfreaks.com/topic/68605-no-errors-maybe-a-time-out/#findComment-345169 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.