Caching strategy and apc

29
Caching Strategy & APC Vo Duy Tuan - CEO/Founder From the PHP developer view

description

Presentation about Cache strategy for your website and u

Transcript of Caching strategy and apc

Page 1: Caching strategy and apc

Caching Strategy & APC

Vo Duy Tuan - CEO/Founder

From the PHP developer view

Page 2: Caching strategy and apc

$who_am_I?

My Name is Võ Duy Tuấn PHP 5 Zend Certified Engineer Interests: PHP, Social Network, Optimize Web Works:

Reader.vn CEO/Founder Trainer Freelancer Help customer Optimize & Speed up website

Page 3: Caching strategy and apc

Caching Strategy1

Page 4: Caching strategy and apc

1.1. Web Caching Introduction

Page 5: Caching strategy and apc

1.2. Cache Strategy

Heavy load page/module HIT & MISS ratio. Budget & Technology AJAX SEO friendly Seperating to small tactics

Cache WHERE ? Cache WHAT ? Cache HOW LONG ?

Page 6: Caching strategy and apc

1.2.1. Cache WHERE?

Page 7: Caching strategy and apc

1.2.2. Cache WHAT?

File Code Query Result Object Array String Number …

Page 8: Caching strategy and apc

1.2.3. Cache HOW LONG?

Cache Clear Type: Never Expired Normal Expired Force Expired

“More time caching, less real time data.”

Page 9: Caching strategy and apc

Which cache do you HATE most?

Page 10: Caching strategy and apc

Alternative PHP Cache - APC2

Page 11: Caching strategy and apc

2.1. What is APC?

Free PHP Extension PHP Opcode cache Support User data cache Run on SAME machine with PHP NOT support multi servers

Page 12: Caching strategy and apc
Page 13: Caching strategy and apc

2.2. APC Installation

On linux: pecl install apc

On Windows: Download apc DLL file to PHP extension directory

such as php_apc.dll

Page 14: Caching strategy and apc

2.3. PHP.INI

extension=/home/path/to/apc.so

[apc]

apc.enabled = 1

apc.cache_by_default=0

apc.shm_segments=1

apc.optimization=0

apc.shm_size=128

apc.ttl=7200

apc.user_ttl=7200

Page 15: Caching strategy and apc

phpinfo()

Page 16: Caching strategy and apc

2.4. APC Monitor

Page 17: Caching strategy and apc
Page 18: Caching strategy and apc
Page 19: Caching strategy and apc

2.5. APC Using

Page 20: Caching strategy and apc
Page 21: Caching strategy and apc

2.6. APC Tip

Opcode your web code only Disable APC for PhpMyAdmin

<Directory "/mysite/public_html/">

...

php_admin_flag apc.cache_by_default On

</Directory

<Directory "/mysite/public_html/phpmyadmin/">

...

php_admin_flag apc.cache_by_default Off

</Directory>

Page 22: Caching strategy and apc

2.6. APC Tip..

Cache STRING is better than ARRAY Long Time To Live better than Short Case study:

Caching for Feed System:

Page 23: Caching strategy and apc

BEFORE

Page 24: Caching strategy and apc

BEFORE

Page 25: Caching strategy and apc

ANALYSE

Page 26: Caching strategy and apc

AFTER

Page 27: Caching strategy and apc

Short TTL make fragmentation

Page 28: Caching strategy and apc

Short TTL make fragmentation

Page 29: Caching strategy and apc

It’s time to query …

Thanks you!