Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does memory usage work in PHP when saving images?
    primarykey
    data
    text
    <p>I'm workin on a script that list all images in one directory and then resize and save in another directory.</p> <p>In my shared server, I receive this message:</p> <pre><code>Allowed memory size of 67108864 bytes exhausted (tried to allocate 600 bytes) in... </code></pre> <p>The question is: If PHP can free the memory after each image creation using image_destroy(), why the while loop that save these images get out of the memory limit?</p> <p>--</p> <p>The code just save the images, nothing more. The problem is with the amount of images, not with just one huge image. Each image have no more than 300KB and the script stop in the middle, and there isn't an exact point. Each time it's executed, it stop in some of the images.</p> <pre><code>foreach($images as $image) { $img = PhpThumbFactory::create($image); $img-&gt;adaptiveResize(640, 450); $img-&gt;createWatermark(PATH_TEMPLATE_SITE . 'img/watermark.png'); $img-&gt;save($dirBig . $id . '.jpg','jpg'); } </code></pre> <p>The class used in this script is <a href="http://phpthumb.gxdlabs.com/" rel="nofollow noreferrer">PHPThumb</a>, and have the destructor:</p> <pre><code>public function __destruct () { if (is_resource($this-&gt;oldImage)) { imagedestroy($this-&gt;oldImage); } if (is_resource($this-&gt;workingImage)) { imagedestroy($this-&gt;workingImage); } } </code></pre> <p>I alredy have the same issue saving images with other scripts. I think the problem isn't with this class, or other type of data used in the script.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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