PHP site optimization Demonstrating a Zend framework websiteperformance improvement and optimization.
Areas of improvementApplication FrameworkDatabaseNetwork LatencyIO ContentionCPU UtilizationNetwork ConnectivityOthers
Performance or Scalability. Both?Hiphop (Facebook implementation of php) is high performing but not scalable
Workload distribution of a page request10% web server40% php processing50% database response10-15% improvement easily achievable using a commonly used alternative stack i.e. Nginx + APC + Htmlcaching + Memcache + CDN
ORM optionsActive Record (made popular by Ruby on Rails)Data MapperCollectionDoctrineData access methods used by Yii, CI, Symphony ...
Active Record (AR)It is an object-relational mapping and object- persistence patternIt binds a business object with a relational record (row)AR class maps to a db table (or view)AR instance maps to a db table recordAR instance properties maps to db table record fieldsInstance methods act on a specific record
PregStripos is 2 times faster than pregctype_alnum is 5 times faster than pregCasting “if ($var == (int) $var)” is 5 times faster than preg_match(“/^d*$/”, $var)
Magic methods__get, __set, __callUsed by Soap, data tables, java objectsUse sparingly and avoid too much recursion
Code AccelerationAPC, Zend OptimizerIncrease performance by 3-4 times
QueueQueueing is offloading long running tasks to queuing systemJob Queue GearmanMessage Queue ActiveMQ AWS Simple Queue Service
What not to doCaching should be the last thing to do. (Focus on performance optimization)Avoid LIKE queries. (Try Solr, Zend_Lucene)
What to doMinimize require_once. Use autoloaderHorizontal architecture is better than vertical ex. wide inheritance is better than deep level inheritanceLazy loading / Load on DemandUse diagnostic tools Zend studio profiler, Code Tracing