Saturday, April 28, 2012

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65536 bytes) in ....

The error above was found on a LAMP (Centos 6, Apache, MySQL and PHP 5) environment.

Where is the problem?

Facts:
134,217,728 bytes is equivalent to 128MB. These numbers indicate that a limit of some memory has been reached.

2 power of 16 = 65536
2 power of 27 = 134217728


There some sites that suggest to increase the memory limit of PHP with memory_limit directive in php.ini file. But this will only prolong the problem to another day. How are you going to keep increasing the memory limit?

Possible approach:

  1. Some where along the setup, the application is eating up memory through an infinite loop. Review location of the application file (model) that is causing the error.
  2. It states "Fatal error" and not "Php Fatal error", indicating Apache web server is sending the error instead of PHP. Check if web server was restarted after the memory_limit was increased in the /etc/php.ini file.
  3. Database configuration needs to be edited for large selects or join processing. (High performance Innodb)


Troubleshooting (approach 1):
  1. Use phpinfo() to compare the memory_limit with what was set in php.ini file. Check Loaded Configuration File, did it say which php.ini file was loaded? This file can be placed in many places.
  2. In PHP, apply the memory_get_usage() to display memory in used.
  3. For database related calls, use the function mysql_free_result() to release memory used by variables.
  4. If the memory grows large, it may be possible to remove the object from the memory via the unset() function.
Troubleshooting (approach 3):
  1. Create a large database and execute various calls via the web browser. Sample large database can be found at Wikipedia.

Monday, April 9, 2012

Installing Java on Centos 6

[Updated for Centos 6.3 32bit]

Installation of Java for compilation and the Java Runtime Environment (JRE) for a Centos 6 server. Additional Java applications can be found from rpmforge.

Step 1: At the command line, login and install

yum install java-1.6.0-openjdk-javadoc java-1.6.0-openjdk-devel
# yum install java-1.7.0-openjdk-devel.i686 java-1.7.0-openjdk-javadoc.noarch

The above results in an installation of about 360MB.

Step 2: Verify installation

# java -version
# javac -version

Step 3: Install Java plugin for web browser

yum install icedtea-web

Note Centos 6 environment:

# yum install redhat-lsb
# lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID:    CentOS
Description:    CentOS release 6.3 (Final)
Release:    6.3
Codename:    Final


LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final