Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Basic overview of caching in PHP

Published in: Technology
  • Be the first to comment

  • Be the first to like this


  1. 1. CachingAaron Scherer
  2. 2. Aaron Scherer● Senior Software Engineer atUnderground Elephant● Co-Organizer at San Diego PHP● Founder of Seductive Turtle Inc.● PHP Developer since 2007○ Professionally since 2009● http://www.aaronscherer.meCore Developer of UECode andGroupTopics
  3. 3. Types of Caching● Opcode Cache○ Compiles your code, speeds up execution● Data/User Cache○ Typical Key-Value storage● Reverse Proxy Cache○ Cache in between code and browser● Browser Cache○ Cache on the Browser
  4. 4. Opcode Cache● Caches the bytecode of PHP. Can be storedin Shared Memory for faster reads● Increases speed by 2-7 times● Popular Opcode Caches○ APC - Was supposed to be put in core○ Zend Optimizer+ - Being put in core (5.5)■○ eAccelerator○ XCache○ HipHop - Weird, but awesome
  5. 5. Opcode Cache cont.Most of these have to be installed bycompiling. You can find instructions on therelated project pagesOnce they are installed, after some minorconfiguration, you are done
  6. 6. Data/User Cache● Cache user defined data with a key, for agiven lifetime● Can significantly increase performance○ Strong Hit/Miss ratio● Memory Storage● Popular Data Caches○ APC - Very Fast, Not Distributed, Also Opcode○ Memcached - Fast, Distributed, Awesome○ Redis - Fast, Semi Distributed
  7. 7. Data/User Cache - APC● Advantages○ 4x+ faster than the other caches - No Network Calls○ Also contains Opcode Cache○ Easy● Example
  8. 8. Data/User Cache - Memcached● Advantages○ Distributed○ OOP / Procedural● Example
  9. 9. Data/User Cache - Redis● Advantages○ Distributed○ OOP○● Example
  10. 10. Gateway / Reverse Proxy Cache● Varnish! (Most popular reverse proxy rightnow)● Shared cache across different clients● Same thing as Browsercache, except public● ESI Tags● A lot more...
  11. 11. Browser Cache● Speed up load times for return visitors● Help reduce load/network traffic on servers● Same as reverse proxy, except private● Used by setting HTML meta tags andheaders●● Can be done in PHP with "header()"● Can be done in htaccess withExpires and Headers
  12. 12. Browser Cache - contd● Htaccess method● PHP Method
  13. 13. Conclusion● Cache is important● Pick the right cache for your needs●●● is awesomeIm awesomeI am the Iron Man, and the Batman