Les outils avancés du développeur PHP
À propos de moi
Les outils présentés
MySQL Proxy
MySQL Proxy
Communication client/serveur
SELECT * FROM tab1 WHERE col1 = 42;
MySQL Proxy
Communication client/proxy/serveur
SELECT * FROM tab1 WHERE col1 = 42;
MySQL Proxy
Démo MySQL Proxy
Scripts utilisés: https://github.com/patrickallaert/MySQL-Proxy-scripts-for-devs
MySQL Proxy
Chainage
SELECT * FROM tab1 WHERE col1 = 42;
Wireshark
Wireshark
Logiciel libre d'analyse de protocol/packet sniffer
Anciennement: Ethereal
Wireshark
eth0: 192.168.0.10
lo: 127.0.0.1
Wireshark
eth0: 192.168.0.10
lo: 127.0.0.1
Wireshark
Interface capturée
Filtre de capture
Wireshark
Wireshark
Démo Wireshark
HipHop for PHP
HipHop for PHP
Compilateur de code PHP:
Transforme le code source PHP en C++ pour ensuite être compilé avec g++.
HipHop for PHP
Compilateur de code PHP:
Transforme le code source PHP en C++ pour ensuite être compilé avec g++.
Langage dynamiquement typé
HipHop for PHP
Compilateur de code PHP:
Transforme le code source PHP en C++ pour ensuite être compilé avec g++.
Langage dynamiquement typé
Langage fortement typé
HipHop for PHP
Compilateur de code PHP:
Transforme le code source PHP en C++ pour ensuite être compilé avec g++.
Langage dynamiquement typé
Langage fortement typé
Compilateur strict
HipHop for PHP
Lancer l'analyse:
$ hphp -t analyze --input-dir .
ou pour plus de contrôle:
$ find -name \*.php > filelist.txt
$ vi filelist.txt
$ hphp -t analyze --input-list filelist.txt
HipHop for PHP
running hphp...
creating temporary directory /tmp/hphp_0CQu7i ...
parsing inputs...
parsing inputs took 0'01" (1250 ms) wall time
pre-optimizing...
pre-optimizing took 0'00" (317 ms) wall time
inferring types...
inferring types took 0'00" (835 ms) wall time
post-optimizing...
post-optimizing took 0'00" (271 ms) wall time
saving code errors and stats...
saving stats...
saving stats took 0'00" (71 ms) wall time
all files saved in /tmp/hphp_0CQu7i ...
running hphp took 0'03" (3170 ms) wall time
HipHop for PHP
$ CodeErrorFormatter.php /path/to/CodeError.js
PHPIncludeFileNotFound
================================================================================
/home/patrick.allaert/Projets/ezpublish/autoload.php
26:5 -> 26:31 details: require 'Base/src/base.php'
36:21 -> 36:47 details: include 'ezc/Base/base.php
UseUndeclaredVariable
================================================================================
/home/patrick.allaert/Projets/ezpublish/lib/ezpdf/classes/class.ezpdftable.php
317:128 -> 317:135 details: $colName
/home/patrick.allaert/Projets/ezpublish/kernel/setup/steps/ezstep_site_types.php
736:39 -> 736:51 details: $php_errormsg
TooManyArgument
================================================================================
/home/patrick.allaert/Projets/ezpublish/lib/ezpdf/classes/class.pdf.php
3318:91 details: $this->addText($x, $y, $size, $text, $angle, $adjust, $angle)
Naviguer dans votre code
OpenGrok
OpenGrok
Outil permettant de parcourir du code source qu'il aura préalablement indexé.
Exemple pour le code source du langage PHP:
Démo OpenGrok
GNU Global
GNU Global
Indexer le projet courant:
$ gtags
Rechercher la définition d'un symbole:
$ global -x symbole
Rechercher les utilisations d'un symbole:
$ global -rx symbole
Global façon bash:
$ globash
Bisecting
Bisecting (git)
Permet de découvrir le moment où une régression a été introduite.
$ git bisect start
$ git bisect bad
$ git checkout <une-bonne-revision>
$ git bisect good
# jusqu'à la découverte du mauvais commit:
$ <tester>
$ git bisect (bad|good)
Bisecting (git)
Ou de manière automatique... :)
$ git bisect start
$ git bisect bad
$ git checkout <une-bonne-revision>
$ git bisect good
$ git bisect run <test-script>
Intercepter les appels systèmes effectués
Intercepter les appels systèmes effectués
strace
$ strace -p <pid>
$ strace <program>
-e <expr>: filtre le type d'appels systèmes
-T: affichage du temps pris pour chaque appel système
-c: résume en fin d'exécution des statistiques
Démo strace
Le refactoring en ligne de commande
Le refactoring en ligne de commande
sed (Stream EDitor) a bientôt 30 ans!
Modifier "copyright 1999-2011" par "copyright 1999-2012":
$ sed -i "s/copyright 1999-2011/copyright 1999-2012/g" fichier1 [fichier2] ... [fichiern]
Ou encore, changer le nom de la classe TrucBrol en MachinBidule:
$ sed -i "s/TrucBrol/MachinBidule/g" $(global -r TrucBrol)
Le refactoring en ligne de commande
codemod: Projet Facebook de modification de code en masse
https://github.com/facebook/codemod
Modifier "copyright 1999-2011" par "copyright 1999-2012":
$ codemod.py --extensions php -d . "copyright 1999-2011" "copyright 1999-2012"
Démo codemod
Les modules PECL incontournables
Les modules PECL incontournables
débogage: Xdebug, scream, inclued
profilage: Xhprof, Pinba, Xdebug
monitoring: APM, Pinba, memtrack
callback: funcall, intercept
Environnements: Production, Développement
Questions ?
Merci :)