I’ve got a PHP script running which uses a lot of database from a MYSQL database. Unfortunately it throws a fatal error:
Fatal error: Allowed memory size of XXXX bytes exhausted (tried to allocate 4553173 bytes) in XXXX
Obviously substitute XXXX with whatever it says in your error message.
PHP has a max memory usage set in the php.ini file. It’s not good practice to increase this, but in some cases it can be a good idea to increase the limit on a script per script basis. Ideally you are better looking at your memory usage and try and decrease it that way, but sometimes this just isn’t possible, or you want to increase the limit temporarily so that you can debug. In this case, put the following at the top of your PHP script:
ini_set("memory_limit","16M");In this case we have upped the memory limit to 16Mb. It’s best to only increase it a little as putting it up too high could fry your server, well perhaps not fry, but you know what I mean.
If you want to increase the memory limit on a site wide basis then you could add the following to your .htaccess file (assuming you’re using Apache):
php_value memory_limit 16M
I’ve been using the internet since 1994 when I started university. I built my first website using Fortune City back in 1996, got my first hosting account in 2000, set up a web design business in 2003, but despite many attempts I have never had a blog. Perhaps it’s because I am not a natural writer and not sure who my audience was. I think all these were barriers to me producing a blog. However, as I approach my 35th birthday, I just don’t see these as obstacles any more. At the end of the day my grammar might be bad, my prose awful, and perhaps no one will ever read this blog. I don’t really care, because I am writing this blog primarily for myself.