Caching

1,627 views
1,517 views

Published on

Basic overview of caching in PHP

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,627
On SlideShare
0
From Embeds
0
Number of Embeds
1,000
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Caching

  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)■ https://wiki.php.net/rfc/optimizerplus○ 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○ http://phpmaster.com/an-introduction-to-redis-in-php-using-predis/● 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● http://www.mnot.net/cache_docs/● 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● https://wiki.php.net/rfc/optimizerplus● http://www.mnot.net/cache_docs/● http://phpmaster.com/an-introduction-to-redis-in-php-using-predis/Php is awesomeIm awesomeI am the Iron Man, and the Batman

×