spiffy577 Posted December 27, 2007 Share Posted December 27, 2007 Hello- I wrote a script to process a bunch of images. It creates a dir structure of CUSTOMERSNAME/images/thumbs and copies the respective images into it after resizing them. But for some reason, the script stops processing after about 30 seconds. I thought it was the max execution time or the "set_time_limit(0)" but that didn't work. I start the script from CreateCustomer($name). And btw, there aren't any errors being reported and it is seeing all of the images available. It just STOPS. I host on godaddy if that makes any difference. Btw, I made a few adjustments to this code to remove directory structures and password info but nothing that would effect the code (just in case something looks funny.) Please help. This is for a client and I just CANNOT figure it out... Thanks, Josh <?php error_reporting(E_ALL); ini_set("register_globals", "on"); ini_set("max_input_time", "-1"); ini_set("upload_tmp_dir", "/tmp"); set_time_limit(0); ini_set("max_execution_time","10000000000000"); function delete_directory($dirname) { if (is_dir($dirname)) $dir_handle = opendir($dirname); if (!$dir_handle) return false; while($file = readdir($dir_handle)) { if ($file != "." && $file != "..") { if (!is_dir($dirname."/".$file)) unlink($dirname."/".$file); else delete_directory($dirname.'/'.$file); } } closedir($dir_handle); rmdir($dirname); return true; } 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 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 = $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 createCustomer($name) { $blnSuccess = delete_directory('/home/content/onlineimages/'.$name); if ($blnSuccess) print "<script>alert('".ucfirst($name)." existed. Now erased...');</script>"; createDirStruct($name); makeThumbs($name); // echo '<span class="medHeader">'.$name.' is created!</span>'; } function makeThumbs($name) { $handler = opendir('/home/content/create/tempimages'); $filenum = 1; unlink("/home/content/create/tempimages/old.jpg"); unlink("/home/content/create/tempimages/temp.jpg"); // keep going until all files in directory have been read while ($file = readdir($handler)) { // if $file isn't this directory or its parent, // add it to the results array if ($file != '.' && $file != '..') $results[] = $file; echo $file."<br>"; } closedir($handler); echo "Number of Images: ".count($results)."<br>\r\n"; for ($i=0;$i<=count($results); $i++) { set_time_limit(100); unlink("/home/content/create/tempimages/old.jpg"); unlink("/home/content/create/tempimages/temp.jpg"); unlink("/home/content/create/tempimages/temp2.jpg"); $file = $results[$i]; if (stristr($file, ".jpg")) { $strNum = $filenum + ''; $strNum = str_pad($strNum, 4, "0", STR_PAD_LEFT); echo "Processing: ".$file."<br>"; copy("/home/content/create/tempimages/".$file, "/home/content/create/tempimages/temp.jpg"); copy("/home/content/create/tempimages/".$file, "/home/content/create/tempimages/temp2.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/temp2.jpg", 600, 600); moveFile("/home/content/create/tempimages/old.jpg", "/home/content/onlineimages/".$name."/images/".$name.$strNum.".jpg"); // unlink($file); if (file_exists("/home/content/onlineimages/".$name."/images/thumbs/tn".$name.$strNum.".jpg")) { echo $name.$strNum. " created<br>"; $filenum++; } } } // unlink("tempimages/old.jpg"); // unlink("tempimages/temp.jpg"); // foreach (glob("/home/content/create/tempimages/*.*") as $filename) { // unlink($filename); // } } 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"); } Link to comment https://forums.phpfreaks.com/topic/83330-script-doesnt-finish/ Share on other sites More sharing options...
rajivgonsalves Posted December 27, 2007 Share Posted December 27, 2007 remove all the @ from the beginning of the functions name even if there is an error it will not show if there is an "@" Link to comment https://forums.phpfreaks.com/topic/83330-script-doesnt-finish/#findComment-423951 Share on other sites More sharing options...
spiffy577 Posted December 28, 2007 Author Share Posted December 28, 2007 Yes, I tried that. No errors... I am BAFFLED. If anyone has anything, I would be thrilled! Thanks! Link to comment https://forums.phpfreaks.com/topic/83330-script-doesnt-finish/#findComment-424495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.