spiffy577 Posted December 25, 2007 Share Posted December 25, 2007 Hello- I have a java uploader that uploads a bunch of files (images) to a temporary folder. That isn't the problem. After they are uploaded, a php script processes them. It creates a directory (images) and a thumb directory (images/thumbs), then the script resizes for both the main image and the thumb. Now, for some reason, the script only processes about 100 images (out of the 350+ or so) and then just stops. Now, I know there is an execute time and a file size so I upped them to outrageous amounts. Still no luck. It just stops then stops loading the rest of the script. Not sure why. It seems to time out about 30 seconds in or so. Anyway, the script is below, called with CreateCustomer. Also, I am hosting on Godaddy if that helps. Btw, ignore all of the directory info. I changed it to keep it a bit more private. That part works fine. Thanks for any info! -Josh P.S. Side question, sometimes getimagesize returns 0 as the dimension sizes. Any idea as to why? Tia!!! <?php ini_set("set_time_limit", "1000000"); function resizeImage($filename, $width, $height) { // Content type if (file_exists($filename)) { // Get new dimensions list($width_orig, $height_orig, $type, $attr) = @getimagesize($filename); if ($height_orig == 0 || $width_orig == 0) { $image = open_image($filename); $width_orig = imagesx($image); $height_orig = imagesy($image); } if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } // Resample $image_p = @imagecreatetruecolor($width, $height); $image = @imagecreatefromjpeg($filename); @imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output @imagejpeg($image_p, "/home/content/create/tempimages/old.jpg", 90); } } function open_image ($file) { # JPEG: $im = @imagecreatefromjpeg($file); if ($im !== false) { return $im; } # GIF: $im = @imagecreatefromgif($file); if ($im !== false) { return $im; } # PNG: $im = @imagecreatefrompng($file); if ($im !== false) { return $im; } # GD File: $im = @imagecreatefromgd($file); if ($im !== false) { return $im; } # GD2 File: $im = @imagecreatefromgd2($file); if ($im !== false) { return $im; } # WBMP: $im = @imagecreatefromwbmp($file); if ($im !== false) { return $im; } # XBM: $im = @imagecreatefromxbm($file); if ($im !== false) { return $im; } # XPM: $im = @imagecreatefromxpm($file); if ($im !== false) { return $im; } # Try and load from string: $im = @imagecreatefromstring(file_get_contents($file)); if ($im !== false) { return $im; } return false; } function createCustomer($name, $name2) { set_time_limit(0); $blnSuccess = delete_directory('/home/content/onlineimages/'.$name); if ($blnSuccess) print "<script>alert('".ucfirst($name)." existed. Now erased...');</script>"; createDirStruct($name); makeThumbs($value, $name); // SCRIPT NEVER MAKES IT TO THIS POINT BELOW echo '<span class="medHeader">'.$name.' is created!</span>'; } function makeThumbs($value, $name) { $handler = opendir('/home/content/create/tempimages'); $filenum = 1; // keep going until all files in directory have been read // I TRIED IT THIS WAY TO SEE IF IT WASN'T READING ALL OF THE FILES. IT DOES. while ($file = readdir($handler)) { // if $file isn't this directory or its parent, // add it to the results array if ($file != '.' && $file != '..') $results[] = $file; } // tidy up: close the handler closedir($handler); echo "Number of Images: ".count($results)."<br>\r\n"; for ($i=0;$i<=count($results); $i++) { $file = $results[$i]; if (stristr($file, ".jpg")) { $strNum = $filenum + ''; $strNum = str_pad($strNum, 4, "0", STR_PAD_LEFT); copy("/home/content/create/tempimages/".$file, "/home/content/create/tempimages/temp.jpg"); resizeImage("/home/content/create/tempimages/temp.jpg", 150, 150); moveFile("/home/content/create/tempimages/old.jpg", "/home/content/onlineimages/".$name."/images/thumbs/tn".$name.$strNum.".jpg"); resizeImage("/home/content/create/tempimages/temp.jpg", 600, 600); moveFile("/home/content/create/tempimages/old.jpg", "/home/content/onlineimages/".$name."/images/".$name.$strNum.".jpg"); if (file_exists("/home/content/onlineimages/".$name."/images/thumbs/tn".$name.$strNum.".jpg")) $filenum++; } } } function moveFile($oldfile, $newfile) { if (!rename($oldfile, $newfile)) { echo $oldfile." ".$newfile." failed to copy $file...<br>"; } } function createDirStruct($value) { $value = strtolower($value); mkdir("/home/content/onlineimages/".$value); mkdir("/home/content/onlineimages/".$value."/images"); mkdir("/home/content/onlineimages/".$value."/images/thumbs"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83109-script-taking-too-long-to-execute-resizing-dir-of-images/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 25, 2007 Share Posted December 25, 2007 It would probably help if you set the correct setting. "set_time_limit" does not exist. The correct parameter name is "max_execution_time" - ini_set("set_time_limit", "1000000"); Quote Link to comment https://forums.phpfreaks.com/topic/83109-script-taking-too-long-to-execute-resizing-dir-of-images/#findComment-422890 Share on other sites More sharing options...
spiffy577 Posted December 28, 2007 Author Share Posted December 28, 2007 Yeah caught that. I changed it. Didn't work. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/83109-script-taking-too-long-to-execute-resizing-dir-of-images/#findComment-424499 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.