PHP memory limit

Can anyone give me a quick guide on using memory resources? I know that I can limit the PHP memory limits in PHP.ini, and also through lines of code, for example:

    ini_set("memory_limit","24M");

I have an image loading script that I am writing that uses a pretty cool PHP script called simpleImage, which can be found here: http://www.white-hat-web-design.co.uk/articles/php-image- resizing.php

I have a basic form that accepts jpg and png. I set the flash memory limit to 24 meters, believing that it would be high enough, but when I tried to upload a 3 MB image, I still got an excellent memory allocation error. Inclining the value to a more meaty 240M, and the script works fine (locally).

My script does this:
1) Accepts the loaded TMP image
2) Runs getimagesize () on the image to verify that it is a valid image.
3) Moving the temporary image to the destination destination directory.
4) Uploads an image using a simple image.
5) Resizes the image using a simple image.
6) Saves the modified image using a simple image script.

So, I assume that downloading / checking / resizing requires a bit larger than 24M. But I'm worried about what an acceptable distribution of memory limits will be. I would like users to be able to upload ~ 6 MB of images. Will it be very stressful on your medium dedicated servers?

script.. ??

    if (!empty($_FILES)) {
    // get image
    ini_set("memory_limit","24M");
    require_once('simpleImage.php');
    require_once('db.php');
    $tempFile             =     $_FILES['file']['tmp_name'];
    $originalFile        =    $_FILES['file']['name'];
    $extension             =     strtolower(end(explode(".", $originalFile)));
    $targetFile         =    "path/to/directory/";

    // validate image
    $validExtensions    =    array('jpg', 'jpeg', 'png');
    if(in_array($extension, $validExtensions)) {
        $validExtension        =    true;    
    } else {
        $validExtension        =    false;    
    }

    if(getimagesize($tempFile) == false) {
        $validImage        =    false;    
    } else {
        $validImage        =    true;    
    }


    if($validExtension == true && $validImage == true) {
        if(move_uploaded_file($tempFile,$targetFile)) {

            $image = new SimpleImage();
            $image->load($targetFile);
            $image->resizeToWidth(500);
            $image->save($targetFile);
        }
    } 
}
+3
4

, JPG PNG, , , 3 , , , 6 , 24 . PHP 30 .

, . megapixels * 3 MB RGB (JPEG PNG) megapixels * 4 MB RGBA ( PNG). , GD , .

+3

, , , .

, . , 3000x3000 jpeg 3 , 3000x3000x3 (3 RGB) 27 , -, 36 . , , .

, - , , ini_set . php.ini, . , , , ini_set("memory_limit","240M") .

+2

, , 6- . , , DSL , . 40-60kbyte/. , , Ethernet- (100 ), 200 60 /.

, . , , PHP , .

, 1 , , . , script, , , . ( Apache php_value) PHP php.ini - , script ini_set('memory_limit', ...), ( - ).

+2

SimpleImage is probably not very effective. In fact, the standard for image processing inside ImageMagick programs . It is written in C and therefore very efficient. It is also widely used and well tested. See this page on php.net for installation and use instructions in PHP.

0
source

Source: https://habr.com/ru/post/1766505/


All Articles