Performance Tips
Quick Links
This page is a small collection of some tips to help increase performance of you PHP code. Most of them require that you have enough control of the server to be able to change settings in Apache and load different PHP extensions.
Opcode Caching
Under normal operation, PHP will load each source code file upon each request. The source code files are first compiled into PHP opcodes and then the opcodes are executed. A number of PHP opcode caching extensions exist that keep the compiled opcodes stored in memory and only regenerate the opcode if the source code changes.
Mike Willbanks has a comparison of APC, eAccelerator and XCache from late 2007.
Class Loading
The special function __autoload() is called (if defined) passing the missing class name. This makes development more friendly since there is no need to explicitly include each class file. The downside of using an __autoload() function is that the loaded classes will not be cached by an opcode cache (if installed).
If you are using an opcode cache you will most likely get better performance using include statements like below.
// Customize this to your flourish root directory $root = $_SERVER['DOCUMENT_ROOT'] . '/inc/flourish/'; // Load the exceptions in their inheritance order include($root . 'fException.php'); include($root . 'fExpectedException.php'); include($root . 'fEmptySetException.php'); include($root . 'fNoRemainingException.php'); include($root . 'fNoRowsException.php'); include($root . 'fNotFoundException.php'); include($root . 'fValidationException.php'); include($root . 'fUnexpectedException.php'); include($root . 'fConnectivityException.php'); include($root . 'fEnvironmentException.php'); include($root . 'fProgrammerException.php'); include($root . 'fSQLException.php'); // The rest of the classes can be loaded alphabetically include($root . 'fActiveRecord.php'); include($root . 'fAuthorization.php'); include($root . 'fBuffer.php'); include($root . 'fCache.php'); include($root . 'fCookie.php'); include($root . 'fCore.php'); include($root . 'fCRUD.php'); include($root . 'fCryptography.php'); include($root . 'fDatabase.php'); include($root . 'fDate.php'); include($root . 'fDirectory.php'); include($root . 'fEmail.php'); include($root . 'fFile.php'); include($root . 'fFilesystem.php'); include($root . 'fGrammar.php'); include($root . 'fHTML.php'); include($root . 'fImage.php'); include($root . 'fJSON.php'); include($root . 'fMailbox.php'); include($root . 'fMessaging.php'); include($root . 'fMoney.php'); include($root . 'fNumber.php'); include($root . 'fORM.php'); include($root . 'fORMColumn.php'); include($root . 'fORMDatabase.php'); include($root . 'fORMDate.php'); include($root . 'fORMFile.php'); include($root . 'fORMJSON.php'); include($root . 'fORMMoney.php'); include($root . 'fORMOrdering.php'); include($root . 'fORMRelated.php'); include($root . 'fORMSchema.php'); include($root . 'fORMValidation.php'); include($root . 'fRecordSet.php'); include($root . 'fRequest.php'); include($root . 'fResult.php'); include($root . 'fSchema.php'); include($root . 'fSession.php'); include($root . 'fSMTP.php'); include($root . 'fSQLTranslation.php'); include($root . 'fStatement.php'); include($root . 'fTemplating.php'); include($root . 'fText.php'); include($root . 'fTime.php'); include($root . 'fTimestamp.php'); include($root . 'fUnbufferedResult.php'); include($root . 'fUpload.php'); include($root . 'fURL.php'); include($root . 'fUTF8.php'); include($root . 'fValidation.php'); include($root . 'fXML.php');
Extensions
A few of the Flourish classes provide pure PHP implementations of functionality that is also available from extensions that are not installed by default. Below is a list of the classes and the extension that will provide better performance.
| Class | Extension |
| fJSON | json (included in 5.2 by default) |
| fNumber/fMoney | bcmath |
| fUTF8 | mbstring |
