0

I added multiple file upload on my website, but I noticed, that uploaded files eat much RAM on the server and it does not decrease for 1-2 days. I think the reason is incorrect PHP code... I tried to unset all variables but it didn't help. That's my code:

 <?php
if(isset($_POST['upload'])){
  if(count($_FILES['files']['name']) > 0){
        for($i=0; $i<count($_FILES['files']['name']); $i++) {
            $tmpFilePath = $_FILES['files']['tmp_name'][$i];
            if($tmpFilePath != ""){
                $max_filesize = 10000288;
                if(filesize($_FILES['files']['tmp_name'][$i]) > $max_filesize) 
                    die('File is too large.'); 
                if($_FILES['files']['type'][$i] != "image/jpeg" AND $_FILES['files']['type'][$i] != "image/png")
                    die('This is not available format.');         
                $shortname = $_FILES['files']['name'][$i];
                $filePath = "img/uploaded_images/full/" .date('d-m-Y-H-i-s').'-'.$_FILES['files']['name'][$i];
                if(move_uploaded_file($tmpFilePath, $filePath)) {

                    $files[] = $shortname;
                    $tmpFilePath = NULL;
                    $allowed_filetypes = NULL;
                    $max_filesize = NULL;
                     $filePath = NULL;
                     $_FILES['files']['name'][$i] = NULL;
                     $shortname = NULL;
                     $_FILES['files']['tmp_name'][$i] = NULL;
                     unset( $tmpFilePath);
                     unset($allowed_filetypes);
                     unset($max_filesize);
                     unset($filePath);
                     unlink($_FILES['files']['name'][$i]);
                     unset($_FILES['files']['name'][$i]);
                     unset($shortname);
                     unset($_FILES['files']['tmp_name'][$i]);
                }
              }
        }

            $_FILES = NULL;
            unset($_FILES);
    } 
} ?>
  • Its unlikely that the php script is eating up the ram, as the script will stop running once its finished. Unless you have some endless loop? So most likely what you are seeing on the server is the filesystem using the ram to cache those files in ram. – user5542121 Nov 20 '15 at 11:48
  • And where filesystem usually saves those cache files? How can I control it? – Levan Lazviashvili Nov 20 '15 at 11:56
  • To make sure that is the case, are you using Linux? – user5542121 Nov 20 '15 at 11:57
  • I use shared hosting on linux, but I'm not sure If I have access to command line... – Levan Lazviashvili Nov 20 '15 at 12:16
  • http://stackoverflow.com/questions/24643807/understanding-buffers-cache-in-linux-free-m If its indeed Linux caching the files, then you don't need to worry about it. As it will automatically free memory if something else needs it. But still possible its something else. – user5542121 Nov 20 '15 at 12:28

0 Answers0