apc - igmigm.univ-mlv.fr/~dr/xpose2014/apc/downloads/apc_by_amc.pdf · - pré requis à connaître...

25
APC Cache PHP alternatif Présenté par : MASLINE-CAMERINI Antoine 1

Upload: others

Post on 27-Jul-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

APC Cache PHP alternatif

Présenté par : MASLINE-CAMERINI Antoine 1

Page 2: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

- Pré requis à connaître

- Introduction

- Principe de fonctionnement

- Installation

- Utilisation

- Comparatif

- Conclusion

Plan de la présentation

2

Page 3: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

- Php : Langage utilisé pour produire des sites web dynamique.

Pré requis à connaitre

HTML PHP

Serveur de bases de données

Serveur d ’applications

Client

HTTP

POST/GET

Connexion PHP

Requêtes SQL

Pages HTML $Résultat

Navigateur web Apache + PHP 3

Page 4: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Pré requis à connaitre

Quelques petites particularités :

- Code écrit entre « <?php » et « ?> »

- langage non typé

- Variable commençant par $ (exemple : $variable = "ok")

- foreach ($array_expression as $key => $value)

{ /* commandes */ }

4

Page 5: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Pré requis à connaitre

5

Page 6: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Signification d’APC ?

-> Alternative PHP Cache

But ?

-> Accélérer la génération de scripts PHP.

Introduction

6

Page 7: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Principe de fonctionnement

Script PHP Parsing PHP

Compile

Cache OpCode « APC »

Execute

Output Page HTML

7

Page 8: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Benchmark avec Firebug APC sur Symphony 2.4

SANS APC

AVEC APC

Principe de fonctionnement

8

Page 9: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

- Avec de la chance votre hébergeur propose déjà

cette extension.

- Sinon :

- Demander à votre hébergeur de l'installer.

- Disposer de votre propre serveur dédié.

Installation

9

Page 10: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Installation sous Linux :

Pour php < 5.5

>> sudo apt-get install php-apc

>> sudo nano /etc/php5/apache2/php.ini

Pour php >= 5.5 (OPCache Natif)

>> sudo apt-get install php-apcu

>> sudo nano /etc/php5/apache2/php.ini

Installation (1/3)

10

Page 11: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Pour php < 5.5

Installation (2/3)

Ligne à ajouter

11

Page 12: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Pour php >= 5.5

Dans php.ini

>> zend_extension=/usr/lib/php5/20100525/opcache.so

>> opcache.enable=1

Dans /etc/php5/mods-available/apcu.ini

>> extension=apcu.so

Redémarrer Apache :

>> /etc/init.d/apache2 restart

Installation (3/3)

12

Page 13: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Propriété dans « php.ini »

- apc.enabled : Activer / désactiver APC.

- apc.shm_size : La taille en mémoire attribué à APC

- apc.optimization : Degré d'optimisation

- apc.filters : Expressions rationnelles séparées par des virgules.

Exemple : apc.filters = "(exemple|index|favori\.php) »

- apc.cache_by_default : Utilisation du cache par défaut

Exemple : apc.cache_by_default = 0

apc.filters="+(exemple|index|favori\.php) »

- apc.ttl : nombre de secondes pendant lesquelles le cache sera conservé.

Utilisation

13

Page 14: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Exemple d’utilisation :

Utilisation

14

Page 15: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Fonctions les plus utilisées

- Mettre en cache une variable (apc_add | apc_store)

- Récupérer une variable en cache (apc_fetch)

- Vérifier si une variable exist (apc_exists)

- Effacer une variable dans le cache (apc_delete)

- Supprimer le cache(apc_clear_cache)

- Mettre à jour une variable (apc_cas)

- Incrémenter/décrémenter une variable (apc_inc | apc_dec)

- Compiler un fichier (apc_compile_file)

- Supprime un fichier du cache (apc_delete_file)

Utilisation

15

Page 16: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Benchmark avec Apache-Benchmark

Sans l’utilisation d’un cache

Utilisation

16

Page 17: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Benchmark avec Apache-Benchmark

Avec l’utilisation d’un cache fichier

Utilisation

17

Page 18: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Benchmark avec Apache-Benchmark

Avec l’utilisation d’APC

Utilisation

18

Page 19: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

- apc_cache_info : Récupère les informations du cache et les métadonnées depuis

le magasin APC.

- apc_sma_info : Récupère les informations d'allocation mémoire partagée d'APC.

Utilisation

19

Page 20: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Exemple d’utilisation :

Utilisation

20

Page 21: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Comparatif de cache

La comparaison des caractéristiques :

21

Page 22: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Comparatif de cache

Tableau de compatibilité :

22

Page 23: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

Conclusion

APC

Facile à

installer Gain énorme

de vitesse

Facile à

utiliser Très utilisé

23

Page 24: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

24

Merci de votre attention

Page 25: APC - IGMigm.univ-mlv.fr/~dr/XPOSE2014/apc/downloads/apc_by_amc.pdf · - Pré requis à connaître - Introduction - Principe de fonctionnement - Installation - Utilisation - Comparatif

- http://php.net/manual/fr/book.apc.php

- http://en.wikipedia.org/wiki/List_of_PHP_accelerators

- http://www.inmotionhosting.com/support/website/what-is/speed-up-php-with-apc

- http://www.ricardclau.com/2013/03/apc-vs-zend-optimizer-benchmarks-with-symfony2/

- http://forum.phalconphp.com/discussion/2594/opcached-php-frameworks-perform-

better-than-phalcon

- http://getgrav.org/blog/mac-os-x-apache-setup-mysql-vhost-apc

- http://blog.nicolashachet.com/gestion-de-caches/optimisation-web-php-des-caches-a-tous-les-niveaux/

- http://www.stephane-raymond.com/blog/webperf/caching-avance/

- http://www.woueb.net/2011/04/11/accelerateur-php-apc/

Sources

25