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
Network LatencyHow to identify?When both page response and CPU usage are slowReasons?DNS Reverse Lookups, TCP Handshakes, High number of hopsTools?Tcpdump, ping, traceroute ..
DNS Reverse LookupsUse ipaddress wherever possible
TCP HandshakesUse persistent connections to remote/local- network services wherever possible
Number of HopsTry to put servers on same switch or in the same LAN.Physical layer and network layer trade offs to be avoided
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
Active Record Issues
Data Patterns in Zend Framework Zend_Controller_Front Singleton FrontController Zend_Db_Table Table Data Gateway Zend_Log Factory Method Adapter
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