Fatal error: Allowed memory size of 8388608 bytes exhausted.
Sometime PHP script may returns the above error. Normally this error is generated when your script exhausted and used up the default memory requirement of 8 MB memory allocation.
* Default memory limit is set in php.ini file ( php configuration file.)
* memory_limit = 8M;
How can we manage with the memory problems comes in some php scripts?
you should check following things when such kind of memory errors occurs in your script.
1. check the default memory_limit variable in your php.ini file.
memory_limit = 8M;
you can change this memory limit and again check for the error.
a. Edit in php.ini
memory_limit = 12M;
restart the apache service.
b. code Level
@ini_set('memory_limit', '12M');
c. htaccess
php_value memory_limit 12M
___________________________________________________________________
2. If the error is not resolved after above step, then you should start debugging your code in order to find out the reason of memory limit exceed.
You have to first find out at what position in your code the memory limit is exceeding. you can use the php's built in function for this purpose.
Function description
memory_get_usage — This function returns the amount of memory allocated to PHP.
Syntax : int memory_get_usage ( true / false );
It returns the amount of memory, in bytes, that's currently being allocated to your PHP script.
Set the option to this function to TRUE to get the real size of memory allocated from system. If not set or FALSE only the memory used by emalloc() is returned.
How to use this function
1. Write this code ( echo memory_get_usage( true ); ) repeteadly after some no of lines.
2. Run it in browser
3. Compare the counts given by each echo and you can check which block of your code needs extra memory.
4. Once you identify the block of code which needs extra memory then you can start deallocating the unused memory spaces allocated by some unused variables and some infinite loops.
5. use following wherever necessary.
a. unset($var_name);
b. mysql_free_result($result_set); — Free result memory
c. Look for include("file.php") in loops, by mistake.
Just try to free the memory everywhere if the variable / array is no longer used.
6. Best of luck.
Function description
bool mysql_free_result ( resource $result )
It frees all the memory associated with the result identifier result .
Tuesday, February 23, 2010
Fatal error: Allowed memory size of 8388608 bytes exhausted.
Labels:
Php
Object Oriented Programming with PHP
Object Oriented Programming With PHP 5 #1[gigya width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=oop1-090302214803-phpapp02&stripped_title=object-oriented-programming-with-php-5-1" quality="high" wmode="tranparent" ]
Labels:
Php
Object Oriented Programming with PHP
Object Oriented Programming With PHP 5 #2[gigya width="455" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=oop2-090302220926-phpapp02&stripped_title=object-oriented-programming-with-php-5-2" quality="high" wmode="tranparent" ]
Labels:
Php
BASIC COMPUTER OPERATIONS
1. Input: This is the process of entering data and programs in to the computer system. You should know that computer is an electronic machine like any other machine which takes as inputs raw data and performs some processing giving out processed data. Therefore, the input unit takes data from us to the computer in an organized manner for processing.

Fig. 2.1 Basic computer Operations
2. Storage: The process of saving data and instructions permanently is known as storage. Data has to be fed into the system before the actual processing starts. It is because the processing speed of Central Processing Unit (CPU) is so fast that the data has to be provided to CPU with the same speed. Therefore the data is first stored in the storage unit for faster access and processing. This storage unit or the primary storage of the computer system is designed to do the above functionality. It provides space for storing data and instructions.
The storage unit performs the following major functions:
3. Processing: The task of performing operations like arithmetic and logical operations is called processing. The Central Processing Unit (CPU) takes data and instructions from the storage unit and makes all sorts of calculations based on the instructions given and the type of data provided. It is then sent back to the storage unit.
4. Output: This is the process of producing results from the data for getting useful information. Similarly the output produced by the computer after processing must also be kept somewhere inside the computer before being given to you in human readable form. Again the output is also stored inside the computer for further processing.
5. Control: The manner how instructions are executed and the above operations are performed. Controlling of all operations like input, processing and output are performed by control unit. It takes care of step by step processing of all operations in side the computer.
Fig. 2.1 Basic computer Operations
2. Storage: The process of saving data and instructions permanently is known as storage. Data has to be fed into the system before the actual processing starts. It is because the processing speed of Central Processing Unit (CPU) is so fast that the data has to be provided to CPU with the same speed. Therefore the data is first stored in the storage unit for faster access and processing. This storage unit or the primary storage of the computer system is designed to do the above functionality. It provides space for storing data and instructions.
The storage unit performs the following major functions:
- All data and instructions are stored here before and after processing.
- Intermediate results of processing are also stored here.
3. Processing: The task of performing operations like arithmetic and logical operations is called processing. The Central Processing Unit (CPU) takes data and instructions from the storage unit and makes all sorts of calculations based on the instructions given and the type of data provided. It is then sent back to the storage unit.
4. Output: This is the process of producing results from the data for getting useful information. Similarly the output produced by the computer after processing must also be kept somewhere inside the computer before being given to you in human readable form. Again the output is also stored inside the computer for further processing.
5. Control: The manner how instructions are executed and the above operations are performed. Controlling of all operations like input, processing and output are performed by control unit. It takes care of step by step processing of all operations in side the computer.
Labels:
Computer Organization
Monday, February 22, 2010
How to get current page URL using PHP?
<?php
function currentPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
You can now get the current page URL using the line:
<?php
echo currentPageURL ();
?>
function currentPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
You can now get the current page URL using the line:
<?php
echo currentPageURL ();
?>
Labels:
Php
Thursday, February 18, 2010
Date format converting Code In PHP
In database date are stored with a format like 0000-00-00.But sometime we need to change the format.The following function help you to change the time format.
function dateFormat($Date)
{
$Date =explode("-",$Date);
$new_date= $Date[2]."/".$Date[1]."/".$Date[0]; //date format will be like21/12/2010
return $new_date ;
}
function dateFormat($Date)
{
$Date =explode("-",$Date);
$new_date= $Date[2]."/".$Date[1]."/".$Date[0]; //date format will be like21/12/2010
return $new_date ;
}
Labels:
Php
Breaking a big array into small parts
<?php
$smallarray1=array_slice($bigarray, 0, sizeof($bigarray) / 2);
$smallarray2=array_slice($bigarray, sizeof($bigarray) / 2);
?>
$smallarray1=array_slice($bigarray, 0, sizeof($bigarray) / 2);
$smallarray2=array_slice($bigarray, sizeof($bigarray) / 2);
?>
Labels:
Php
Subscribe to:
Posts (Atom)