Welcome Guest, Not a member yet? Register   Sign In
CI 2.0 upload library: memory_limit
#1

[eluser]Bas Vermeulen[/eluser]
I have a question about the do_xss_clean() function of the upload library. This function starts with checking the current memory limit, adds the file size and updates the memory limit with the new value (old value + file size).

File: system/libraries/Upload.php (@ bitbucket)
Code:
if (function_exists('memory_get_usage') && memory_get_usage() && ini_get('memory_limit') != '')
        {
            $current = ini_get('memory_limit') * 1024 * 1024;

            // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output
            // into scientific notation.  number_format() ensures this number is an integer
            // http://bugs.php.net/bug.php?id=43053

            $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', '');

            ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net
        }

My memory_limit is set @ 256mb,which should be much more then enough. But this script doesn't check if their is enough, it always adds the file size and tries to update the memory_limit. Ofc we set a max value, so for every upload our server returns an error: ALERT - script tried to increase memory_limit to 268480769 bytes which is above the allowed value.

This is kinda annoying, can someone explain why this function works like this? Is it a bug or is there a special reason for doing it like this?

Thanks in advance for your thoughts!
#2

[eluser]teampoop[/eluser]
I think memory_limit is one of those configuration items that you can not change on the fly. Either you have to update it via the php.ini.


but I could be wrong.
#3

[eluser]smilie[/eluser]
If Apache allows it, you can change memory limit 'on the fly'. AllowOverride must be then set for that domain.

Cheers,
Smilie
#4

[eluser]Bas Vermeulen[/eluser]
Thanks for the replies. I know memory limits can be set on the fly. That's not the point. I want to know why this is implemented like this? We set a maximum memory usage because we don't want the scripts to be able to use / abuse more of our server's memory. This scripts always updates the memory_limit to a value higher then allowed and thereby will always generate the given warning.

The reason for this implementation is totally unclear to me. 256mb should be more than enough memory to be able to complete this function... why the need to always higher the memory_limit? Isn't it better to check the memory_limit and update it to a higher value if it is to low?
#5

[eluser]Bas Vermeulen[/eluser]
Maybe one of the CI developers would like to elaborate on this?




Theme © iAndrew 2016 - Forum software by © MyBB