Tuesday, February 23, 2010

Fatal error: Allowed memory size of 8388608 bytes exhausted.

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 .

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" ]

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" ]

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.

f1.gif (4622 bytes)

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.

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 ();
?>

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 ;

}

Breaking a big array into small parts

<?php

$smallarray1=array_slice($bigarray, 0, sizeof($bigarray) / 2);
$smallarray2=array_slice($bigarray, sizeof($bigarray) / 2);

?>

Code for Fav icon

<LINK REL="SHORTCUT ICON" href="images/shortcut.jpg" />

how to get File extention using PHP

<?php

$file_extension = strtolower(substr(strrchr($filename,"."),1));

?>

Monday, February 1, 2010

Essential Joomla Extensions

Artio JoomSEF – Artio.cz


This extension will rewrite your Joomla! URLs into a more human friendly form, which at the same time enhances its SEO value. A multi-language interface    support is included, and updates can be made online easily. It also offers API for adding SEF functionality for other 3rd party Joomla! Modules easily. This is a great plug-in for Joomla! Users who wish to make their


Sites more prominent in the search engines.


Download Here:


http://www.artio.cz/en/downloads/joomla-extensions/



AllVideosPlugin - Joomlaworks.gr


The AllVideos Plugin gives you the ability to easily embed online streaming videos/audios within your webpage as well as have your own videos/audios uploaded on your server. No HTML is required at all and all you have to do is to place tags within our content where you want the videos or audios to appear. There are two ways you can use the AllVideosPlugin. If you want to save on your bandwidth, simply upload your videos to a Youtube.com and then embed the video onto your own webpage with the plugin. An alternative will be upload the


video itself to your website, after which you can stream the audios/videos via simple tags. One common complaint is that only 10 videos are allowed per page for this plugin. As long as that is not a problem, the AllVideosPlugin is very useful for all your videos/audios streaming needs.


Download Here:


http://www.joomlaworks.gr/


Jombackup - Jomres.net


Jombackup is an extension used for performing daily mysql backups and emailing them to an address of your choice. You can use the cron jobs function to enable daily backups Joomla! mySQL data. This is a must-have extension to saveguard all your precious data in your databases. It is easy to install as well, and works like a charm.


Download Here:


http://www.jomres.net/index.php?option=com_docman&task=doc_details&gid=72&Itemid=7


9


Phil-A-Form - Phil-taylor.com


Phil-A-Form allows you to generate dynamic forms in Joomla!, without sophisticated programming knowledge. Results can be emailed to anyone, or saved in a database. Phil-AForm was the worlds FIRST EVER mambo/Joomla! Form Generator, and is extremely beginnerfriendly as well. Solid and reliable, a great extension if you need forms on your site.


Download Here:


http://www.phil-taylor.com/Joomla/Components/Phil-A-Form/


VirtueMart - Virtuemart.org


VirtueMart is the leading Online-Shop solution for Joomla! (more than 1.5 Million downloads so far). You can download, use and modify it without any restrictions, for free, just like Joomla!. VirtueMart is not a stand-alone script, but a Plug-in and requires the PHP Content Management System Joomla!. Multiple translations can be readily found in the included


Language pack.


Download Here:


http://www.virtuemart.org/


AdSense Module (ClickSafe - Special Edition) - Joomlaspan.com


This extension is simple solution for implementing Google AdSense ads in Joomla!. As they are, Adsense ads are supposed to be easy to insert by themselves, but this extension provides other useful functionalities like blocking certain IP numbers from seeing Google ads. This helps prevent click fraud as you cannot accidentally click on your own ads. It also has chameleon codes that can make the ad colors automatically change with each page load, as determined


by you.


Download Here:


http://www.joomlaspan.com/joomla-downloads/Download/-JoomlaspanModules/GoogleAdSenseRelatedModules/