Webby Awards, Time Magazine's "25 Web Sites We Can't Live Without" and PC Magazine's "Top 100 Web Sites"
Statistics:
Our Stack
|
|
These are foolish endeavors most of time (unless you are Facebook)
My goal today is to show you some of the things we did to compromise the flexibility of ZF with the performance we wanted & the horizontal scalability we needed. Won't be showing a terribly large amount of code, just enough to demonstrate the point. Any apparently useless activity which, by allowing you to overcome intermediate difficulties, allows you to solve a larger problem.
If you are not using opcode caching (APC, Wincache, Zend Optimizer+) you're missing out.
How easy is APC to install? apt-get install php5-apc on ubuntu or pecl install apc
Heavy processing should be run in the background, there are several ways to do this here are some:
Not going into this hardcore, entire tutorials are built on this subject. Good examples for things to process in the background, api calls to register or update information externally, processing on uploads, Indexing of content, etc
Matthew Turland wrote an interesting blog post about Zend Framework 1 Forms & the Plugin Loader which will aide with Forms in larger implementations, his post:
Compromise here was that we now have to generate a classmap upon deployment. Remember to strip out include_once statements in ZF, these will include every tid bit of framework with them.
I strongly strongly strongly strongly advise moving to the ZF2 psr0 and classmap autolaoders, there are some strong problems with the ZF1 Autoloader.
Here's what the Zend Framework guide says on how to optimize the Include Path (if you absolutely have to use it)
Should be stripped out.
find . -name '.php' -not -wholename '/Loader/Autoloader.php' -not -wholename '*/Application.php' -print0 | xargs -0 sed --regexp-extended --in-place 's/(require_once)/// 1/g'
Check your httpd.conf and see how many modules exist in there that you technically don't need to use.
This has several benefits, the request object is available in various places so it's given us a chance to abstract API key's and the such out of code into an object that's generally available. Can't really cache ini files (Zend_Config uses readfile for this).
Problems with Zend Config
We can do this better
$config = require(APPCLIATION_PATH . '/configs/application.php');
$application = new Zend_Application(
APPLICATION_ENV,
$config
);
The File
<?php
return array(
'key' => 'value'
);
--or--
<?php
$config = array()
if (APPLICATION_ENV == 'development')
{
$config['key'] = 'value';
}
return $config;
This is kind of what's going on in ZF2, it's a lot faster since you're not compiling a Markup to the language & APC will cache this.
Replace apc_fetch/apc_store with memcache::get/memcached::set, wincache_ucache_add/wincache_ucache_get, etc.
$config = apc_fetch('my_config');
if (!(is_array($config)) {
require_once 'Zend/Config/Ini.php';
$section = APPLICATION_ENV;
$filename = APPLICATION_PATH . '/configs/application.ini';
$config = new Zend_Config_Ini($filename, $section);
$config = $config->toArray();
apc_store('my_config', $config, 600);
}
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
$config
)
I know we don't use Zend Config but Rob Allan (Akrabat) has given this tip and it's very valid.
Why?
This is where it becomes important to remember we rewrote this to suit our needs, we have well over 900 thousand urls in our system, at this point it would have been a bit ridiculous to try to update a configuration file with each new additional URL plus it would have taken significant space in memory. The cost of querying the database and waiting for a response here was far cheaper than it would have been to use the loop structure that ZF1 uses currently.
We use Memcache, some of the things we cache:
I put this last because it's probably the biggest thing you can do to improve your performance. If you attended Ralph's Session on ZendCode yesterday this is a very similar premise.
Just a quick summary:
| Table of Contents | t |
|---|---|
| Exposé | ESC |
| Full screen slides | e |
| Presenter View | p |
| Source Files | s |
| Slide Numbers | n |
| Toggle screen blanking | b |
| Show/hide slide context | c |
| Notes | 2 |
| Help | h |