bpops Posted February 21, 2008 Share Posted February 21, 2008 Hi, I've written a script and form for a user to upload a file to my website. It works perfect for relatively small files. But if I get larger (around 10 MB), I get this error: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 12707261 bytes) Now, I have access to php.ini, and I've altered these parameters: memory_limit = 32M max_input_time = 200 upload_max_filesize = 25M post_max_size = 30M So I would think I could have a user upload something up to 25MB. Why do I get this error? I'm especially confused since the amount it is trying to allocate is smaller than the allowed memory size! Is the memory not clearing itself or something? Oh, and this is not live on my site yet, so it's NOT a problem with multiple users uploading large files at once. Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/ Share on other sites More sharing options...
bpops Posted February 21, 2008 Author Share Posted February 21, 2008 Ok, now I'm able to reproduce the same error in a different way. If I make a new file called test.php: //test.php <?php include('test.php'); ?> I get this error. Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 8192 bytes) in /home/scriptcr/public_html/test.php on line 1 Obviously this isn't code I would want to use but it leaves me wondering how the memory is allocated and used. Does anyone know anything about this? Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472442 Share on other sites More sharing options...
weekendWorker Posted February 21, 2008 Share Posted February 21, 2008 Put this in the top of your config code instead of php.ini and see if this works: ini_set("memory_limit","32M"); or better yet : ini_set("memory_limit","50M"); Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472495 Share on other sites More sharing options...
bpops Posted February 21, 2008 Author Share Posted February 21, 2008 Thanks for the response. I still get the same error. I know the php.ini file is working because if I run phpinfo(), all my parameters are set correctly (including the 32M limit). 32M should be more than enough for a 10MB file (I would think!) There must be something I'm not understanding. If anyone else has any thoughts, please let me know. I'm really getting frustrated Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472509 Share on other sites More sharing options...
DyslexicDog Posted February 21, 2008 Share Posted February 21, 2008 Is it possible there's an error in your code...? you should post your code Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472512 Share on other sites More sharing options...
bpops Posted February 21, 2008 Author Share Posted February 21, 2008 Ok, I don't think my code is 'bad' per se, since it works fine for smaller files. But here is a portion of it anyway. Thanks for looking. This is from the page that accepts the form submitted with the file. <?php $script_file = $_FILES['script_file']; // File Attachment $fileatt = $script_file['tmp_name']; $fileatt_type = $script_file['type']; $fileatt_name = $script_file['name']; $file_size = filesize($script_file['tmp_name']); // Check for error if(!$file_size){ $error_text = 'There was a problem uploading your file.'; } /*this catches an error if the file doesn't upload right, but will not catch the memory_limit error */ // Keep filesize under 10MB if($file_size > 10000000){ $error_text = 'File size must be no larger than 10MB.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472515 Share on other sites More sharing options...
weekendWorker Posted February 21, 2008 Share Posted February 21, 2008 Thanks for the response. I still get the same error. I know the php.ini file is working because if I run phpinfo(), all my parameters are set correctly (including the 32M limit). 32M should be more than enough for a 10MB file (I would think!) There must be something I'm not understanding. If anyone else has any thoughts, please let me know. I'm really getting frustrated PHP is trying to allocate 12707261 more bytes "This number is not including" what the file is all ready calling for. I think this equals out to around 20 -22 MB total. Now let's just say you might have a memory leak in your code, then you might get this error. Try to change the values quite higher and try again. Also you may want to check your code for memory leaks. The error is exactly the way it reads. You will have to change the memory size to a higher value to run the code as is. If this don't work look into a few php memory functions to add to your code like : malloc () free() Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472534 Share on other sites More sharing options...
bpops Posted February 21, 2008 Author Share Posted February 21, 2008 weekendWorker, I don't see where those functions are php functions (I do recognize them from C though). PHP.net has no listing for them. And not to beat a dead horse, but while I understand what you're saying about it trying to allocate more memory, it still doesn't make sense to me. I have 32MB for the memory allocation. I'm uploading a single 8MB file. Even if it's allocating twice (or 3x) that filesize for copying purposes (?) it still shouldn't need that much. I recognize that increasing this value might fix the problem, but it seems like a 'band-aid' solution to the problem. I'd rather understand what's going on here. But I do thank you very much since no one else around here has been able to give me any answers either. Alright, to bed with me. Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472536 Share on other sites More sharing options...
weekendWorker Posted February 21, 2008 Share Posted February 21, 2008 These functions are used in PHP also as well as C, but are a part of Zend engine (configuration functions). I don't feel like your beating a dead horse, I have seen this problem on some of my my servers before >> which by the way are shared environments. I guess you could also try caching parts of your script if possible. This might save some memory also. Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472545 Share on other sites More sharing options...
bpops Posted February 21, 2008 Author Share Posted February 21, 2008 bump to see if any morning people might know whats going on here Quote Link to comment https://forums.phpfreaks.com/topic/92219-memory_limit-error/#findComment-472875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.