TZH Posted September 12, 2013 Share Posted September 12, 2013 Hi guys, I'm having this every day: Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 122880 bytes) In my opinion, 256MB of memory shouldn't exhausted so soon, as I only have less than 100 visitor every day... Could this totally my PHP code faulty ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/282099-fatal-error-allowed-memory-exhausted/ Share on other sites More sharing options...
TZH Posted September 12, 2013 Author Share Posted September 12, 2013 (edited) Any chance MYSQL could eat all my memory ? As my code get Mysql query very frequently.. Edited September 12, 2013 by TZH Quote Link to comment https://forums.phpfreaks.com/topic/282099-fatal-error-allowed-memory-exhausted/#findComment-1449240 Share on other sites More sharing options...
mac_gyver Posted September 12, 2013 Share Posted September 12, 2013 (edited) either your php script is doing some processing that is taking a huge amount of memory or you have a logic error that is causing a loop to create variables/array data that consumes all available memory. for us to be able to help, you would need to post your script, from the first line (less any database credentials) up through the point where the error is occurring at and if the error is inside of a loop, post the code through to the end of that loop. Edited September 12, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/282099-fatal-error-allowed-memory-exhausted/#findComment-1449242 Share on other sites More sharing options...
TZH Posted September 12, 2013 Author Share Posted September 12, 2013 Hi, My script content dozen of files, I tried to find any leaking by using memory_get_usage() at the start and end, and reload in browser, but every time are the same usage. Is this going to help me find leaking? If so I should try more in every single file. Quote Link to comment https://forums.phpfreaks.com/topic/282099-fatal-error-allowed-memory-exhausted/#findComment-1449243 Share on other sites More sharing options...
mac_gyver Posted September 12, 2013 Share Posted September 12, 2013 the error message contains a file name and line number. start at that point and work back toward the start of the code. Quote Link to comment https://forums.phpfreaks.com/topic/282099-fatal-error-allowed-memory-exhausted/#findComment-1449244 Share on other sites More sharing options...
priyankagound Posted September 16, 2013 Share Posted September 16, 2013 Here's the full solution in the cleanest possible way: Create a file called php.ini in the root of your site (if you are using a hosted addon domain, this must be in the subdirectory of that site) In php.ini, enter a line that saysmemory_limit = 64MB In your site's .htaccess (being a WordPress blog, I'm assuming there is one), enter the following lineSetEnv PHPRC /<unix path to the directory where php.ini is>/ (keep the slashes) Edit wp-config.php and enter the following linedefine('WP_MEMORY_LIMIT', '64M'); Upload the new files to the server Quote Link to comment https://forums.phpfreaks.com/topic/282099-fatal-error-allowed-memory-exhausted/#findComment-1449683 Share on other sites More sharing options...
trq Posted September 16, 2013 Share Posted September 16, 2013 Here's the full solution in the cleanest possible way: Create a file called php.ini in the root of your site (if you are using a hosted addon domain, this must be in the subdirectory of that site) In php.ini, enter a line that says memory_limit = 64MB In your site's .htaccess (being a WordPress blog, I'm assuming there is one), enter the following line SetEnv PHPRC /<unix path to the directory where php.ini is>/ (keep the slashes) Edit wp-config.php and enter the following line define('WP_MEMORY_LIMIT', '64M'); Upload the new files to the server There has been no mention of Wordpress in this thread. Quote Link to comment https://forums.phpfreaks.com/topic/282099-fatal-error-allowed-memory-exhausted/#findComment-1449691 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.