Tuesday, August 11, 2009

Lazy Loading to improve performance of your php code

See above example code, or event you do like that :D :

require '/class/Database.php';
require '/class/Common.php';
require '/class/Action.php';
require '/class/Template.php';
require '/class/Module.php';


It's not good for server because php engine must load every file when execute, in case of it's not necessary.

define('CLASS_DIR', 'class/')

function autoload($className)

$user = new user();

This message is quoted from "zend certification study guide" :">
"By default, SPL uses its own autoloader, called spl_autoload(); this built-in
function checks all include paths for filenames that match the name of the class
that needs loading in lowercase letters, followed by .inc, .php, or the exten-
sions specified using a comma-separated string as the only parameter to a call to

Regard to function spl_autoload_extensions(), it allow you to define extension of filename.

No comments:

Post a Comment