Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Script stopping abruptly (imagecopyresampled)
    text
    copied!<p>I have this script below that stops without an error after a certain amount of iterations. When the images it is using are ~4MB, the script stops after about 10 iterations. When the images are around 1MB, the script stops after ~30 iterations. When the images are smaller, the script can go for 500 iterations. It doesn't seem to be a timeout, as it happens at a different time count each time.</p> <p>When I test this on my own machine using xxamp, there are no errors, and the script finishes perfectly.</p> <p>I am guessing this is some type of memory problem? I am completely inexperienced and clueless when it comes to memory.</p> <p>EDIT: I put an echo before the imagecopyresampled function and after. The script seems to stop on this function.</p> <p>Here is my loop that goes through each file in the directory:</p> <pre><code>while (false !== ($filer = readdir($handle))) { if (is_file($srcDir . '/' . $filer)) { set_time_limit(20); $counter++; $total = $x; $percent = intval($counter/$total * 100)."%"; // Javascript for updating the progress bar and information echo '&lt;script language="javascript"&gt; document.getElementById("progress").innerHTML="&lt;div style=\"width:'.$percent.';background-color:#333;\"&gt;&amp;nbsp;&lt;/div&gt;"; document.getElementById("information").innerHTML="'.$counter.' images processed."; &lt;/script&gt;'; //location/filename variable $filename = $srcDir . '/' . $filer; // This is for the buffer achieve the minimum size in order to flush data echo str_repeat(' ',1024*64); // Send output to browser immediately flush(); //get the extension of the image $path_parts = pathinfo("$filename"); $ext = strtolower ($path_parts['extension']); $width = 100; $height = 100; // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height &gt; $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_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 the small image imagejpeg($image_p, "$destDir/$filer", 100); //Move the big image rename($srcDir . '/' . $filer, $destDirbig . '/' . $filer); echo $counter; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload