PLUG 5 is currently in development.


This page refers to the original PLUG framework for PHP 4 which is concidered obsolete, and no longer maintained.

Optimising PHP code


The "Compiler" is the most unique feature of the PLUG framework.

The basic premise is that your development site is the original, and any files deployed to a target host are uneditable. This provides various opportunities for optimization and also allows site configurations to be embedded into deployed files transparently.

Many of the things that make development more organized also make for many files being included into a single PHP script execution. ( The PLUG database package alone consists of 12 separate class files. ) PHP is a not a compiled language, that is to say that source code is compiled as it is encountered. This raises questions about the efficiency of opening and executing many run-time inclusions.

The compiler offers various options, so you can either deploy all the include files separately or compile all required files into each top-level script. Javascript libraries can also be included in the same way.

My experiments have shown that standalone PHP files can execute extremely fast indeed, but in some cases it is still desirable to maintain run-time inclusions. PLUG allows great flexibility in mixing these approaches.

A special import() function is used to load a class or package into the current script. In development mode this function includes and executes in the normal way

In addition to the import statement you can choose one of the four PHP inclusion statements (include, include_once, require, require_once) to also insert code directly into the optimised file in this manner. The other three statements will be left alone allowing you to use other code libraries as you wish along side PLUG.

There are various other functions in the import family, such as import_js, and import_static, and this family may continue to grow. More information on these to come.

back to top