Debugging: Rules And Tools - PHPTek 11 Version

2,441 views
2,314 views

Published on

The PHP Tek 11 version of my Debugging: Rules and Tools talk.

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

No Downloads
Views
Total views
2,441
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
33
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Debugging: Rules And Tools - PHPTek 11 Version

  1. 1. DEBUGGINGR U L E S A N D TO O L Sian barber - http://phpir.com - @ianbarber
  2. 2. I did XI wanted YInstead I got Z
  3. 3. http://www.debuggingrules.com
  4. 4. RULE 1UNDERSTANDTHE SYSTEM
  5. 5. BugWiki Tracker Frame work RTFM PHP Docphp.net
  6. 6. $field = $document->getField($fieldName);if ($field->storeTermVector) { /** * @todo term vector storing support */ require_once Zend/Search/Lucene/Exception.php; throw new Zend_Search_Lucene_Exception (Store term vector functionality is not supported yet.);}
  7. 7. KomodoEclipse Zend Studio TOOLS PHP NetStorm Text Beans Mate
  8. 8. RULE 2MAKE ITFAIL
  9. 9. Recreate AndAutomatePHP UnitSimpleTestSeleniumPHP SlimJMeterAb
  10. 10. Time Load Timing UserServer CONTROL Env VARIABLES Request Client DB State Session
  11. 11. [root@localhost ~]# pear channel-discover pear.phpunit.de[root@localhost ~]# pear install phpunit/PHPUnitclass Test_User extends PHPUnit_Framework_TestCase { public function testUpdate() { $r = ("a", "b"); try { $u = User::fetch($this->newName); $result = $u->update($r); } catch (Id_Exception $e) { $this->fail($e->getMessage()); } $this->assertEquals($r, $u->getRoles()); }}
  12. 12. http://seleniumhq.org/
  13. 13. class Example extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl("http://general.dev/"); } public function testMyTestCase() { $this->open("/"); $this->select("locale", "label=de"); $this->waitForPageToLoad("30000"); $this->assertTrue($this->isTextPresent( "Datenbank-Einrichtung")); }}
  14. 14. http://jakarta.apache.org/jmeter/
  15. 15. RULE 3QUIT THINKINGAND LOOK
  16. 16. if($this->hasRoles) { $this->deleteRoles();}try { foreach($submittedRoles as $role) { $this->addRole($role); }} catch(Identity_Exception $e) { $this->log->warn(Role add failed.); throw new Service_Exception_BadRequest( Cannot add user role);}
  17. 17. Instrumentation:Inspect or Report
  18. 18. Xdebug http://www.xdebug.org[root@localhost ~]# pecl install xdebugzend_extension=/usr/lib64/php/modules/xdebug.so
  19. 19. xdebug.profiler_enable=1xdebug.profiler_output_dir=/tmp
  20. 20. Web Server PHP ScriptDebugging Client XDebug Debugging Commands
  21. 21. xdebug.remote_enable=1xdebug.remote_port=9000xdebug.remote_mode=reqxdebug.remote_host=192.168.192.1 # xdebug.remote_connect_back=1
  22. 22. [root@localhost ~]# lsof -p 4365COMMAND USER FD TYPE DEVICE NAMEhttpd apache mem REG 253,0 /lib64/libssl.so.0.9.8ehttpd apache mem REG 253,0 /usr/lib64/php/modules/xdebug.sohttpd apache mem REG 253,0 /usr/lib64/libsqlite3.so.0.8.6[root@localhost ~]# strace -cp 4365Process 6910 attached - interrupt to quitProcess 6910 detached% time seconds usecs/call calls errors syscall------ ----------- ----------- --------- --------- ------------- 36.91 0.037307 466 80 getdents 30.07 0.030393 950 32 7 access 17.04 0.017224 154 112 10 open 5.08 0.005136 12 444 9 lstat 3.87 0.003910 18 213 1 read 3.04 0.003071 29 107 close 2.57 0.002598 1299 2 writev 0.78 0.000785 1 631 stat
  23. 23. [root@localhost ~]# strace -Tp 4365Process 6910 attached - interrupt to quitepoll_wait(16, {{EPOLLIN, {u32=31389672, u64=47128707528680}}}, 2, 10000) = 1 <6.926140>accept(4, {sa_family=AF_INET6, sin6_port=htons(64930), inet_pton (AF_INET6, "::ffff:192.168.192.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [47128676139036]) = 17 <0.000094>fcntl(17, F_SETFL, O_RDWR|O_NONBLOCK) = 0 <0.000035>read(17, "POST / HTTP/1.1rnHost: general.d"..., 8000) = 522 <0.000044>stat("/mnt/hgfs/habari/htdocs/", {st_mode=S_IFDIR|0755, st_size=408, ...}) = 0 <0.000527>open("/mnt/hgfs/habari/htdocs/.htaccess", O_RDONLY) = 18 <0.000457>fcntl(17, F_SETFL, O_RDWR|O_NONBLOCK) = 0 <0.000037>
  24. 24. [root@localhost ~]# strace -Tp 4365Process 6910 attached - interrupt to quitepoll_wait(16, {{EPOLLIN, {u32=31389672, u64=47128707528680}}}, 2, 10000) = 1 <6.926140>accept(4, {sa_family=AF_INET6, sin6_port=htons(64930), inet_pton (AF_INET6, "::ffff:192.168.192.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [47128676139036]) = 17 <0.000094>fcntl(17, F_SETFL, O_RDWR|O_NONBLOCK) = 0 <0.000035>read(17, "POST / HTTP/1.1rnHost: general.d"..., 8000) = 522 <0.000044>stat("/mnt/hgfs/habari/htdocs/", {st_mode=S_IFDIR|0755, st_size=408, ...}) = 0 <0.000527>open("/mnt/hgfs/habari/htdocs/.htaccess", O_RDONLY) = 18 <0.000457>
  25. 25. Zend Drupal Log syslog sfLogger Kohana Logerror_log("Message for the PHP log")error_log("Log to email", 1, "me@foo.com");error_log("Log to a file",3, "/tmp/m.log");error_log("Message for the SAPI log", 4);
  26. 26. MQ Syslog File LOGGING SYSTEMGearman Database Pipe
  27. 27. FirePHP
  28. 28. [root@localhost ~]# pear channel-discover pear.firephp.org[root@localhost ~]# pear install firephp/FirePHPCorerequire_once(FirePHPCore/FirePHP.class.php);ob_start();$firephp = FirePHP::getInstance(true);doStuff($firephp);$firephp->warn(Done Stuff);$firephp->error(An error!);$firephp->log($_GET);ob_end_flush();function doStuff($firephp) { $firephp->trace(Stuff Backtrace); echo "This page intentionally blank";}
  29. 29. RULE 4DIVIDE ANDCONQUER
  30. 30. <?xml version="1.0" encoding="UTF-8"?><phpunit bootstrap="./TestHelper.php"colors="true"> <testsuite name="Commonlib Tests"> <directory>./library/Cl/</directory> <directory>./library/Sso/</directory> </testsuite><filter> <whitelist> <directory suffix=".php">../Sso/</directory> <directory suffix=".php">../Cl/</directory></whitelist></filter></phpunit>
  31. 31. Folder Root CL SSO Auth Client Model UserAdapter Plugin Exception AbstractSSO SFDC Gearman
  32. 32. <?php$worker = new GearmanWorker();$worker->addServer();$worker->addFunction( "allow_access", "allowAccess");$worker->addFunction( "deny_access", "denyAccess");while ($worker->work());
  33. 33. Git Bisectgit bisect startgit bisect badgit bisect good <known good rev>git bisect ?git bisect reset
  34. 34. good bad 1 Request View 2 Front 3Controller Plugin Input Model Filter Controller
  35. 35. Firewall CacheWeb Server Database
  36. 36. Tamper Data Curl FirewallWireshark Cache Netcat Web ServerMySQLProxy Xdebug Database
  37. 37. Tamper Datahttps://addons.mozilla.org/firefox/addon/966
  38. 38. Wiresharkhttp://www.wireshark.org/
  39. 39. [root@localhost ~]# { echo -ne "HTTP/1.0 200 OKrnrn"; cat test.html; } | nc -l 8080GET / HTTP/1.1User-Agent: curl/7.19.7 (i386-apple-darwin10.0.0)libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3Host: general.dev:8080Accept: */*[root@localhost ~]# curl http://general.dev:8080 -v* About to connect() to general.dev port 8080 (#0)* Trying 192.168.192.129... connected* Connected to general.dev (192.168.192.129) port8080 (#0)> GET / HTTP/1.1> User-Agent: curl/7.19.7 (i386-apple-darwin10.0.0)libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3> Host: general.dev:8080
  40. 40. local log_file = mysql.loglocal fh = io.open(log_file, "a+")function read_query( packet ) if string.byte(packet) == proxy.COM_QUERY then local query = string.sub(packet, 2) fh:write( string.format("%sn",query)) fh:flush() endend MySQL Proxy
  41. 41. RULE 5CHANGE ONETHING ATA TIME
  42. 42. [root@localhost ~]#: svn stM index.php[root@localhost ~]#: git stash saveSaved working directory and index state WIPon master: 0e22fdd Initial checkinHEAD is now at 0e22fdd Initial checkin[root@localhost ~]#: git status# On branch masternothing to commit (working directory clean) Source Control
  43. 43. [root@localhost ~]#: svn log .-------------------------------------------r4341 | rickc | 2010-09-24 03:01 | 3 linesDont test if Post::tags is empty beforegetting tags. There may be a performancehit for this. It can be dealt with if it isnoticable. Fixes ticket #1235. Props to ilofor the patch. Note that Post still needs to be updated to use real Tags, not an array of slug/label pairs as the tags member.-------------------------------------------- Source Control
  44. 44. Known Good[root@localhost ~]# diff -yw web.conf web2.conf<VirtualHost *:80> <VirtualHost *:80> ServerAdmin root@e.com ServerAdmin root@e.com DocumentRoot /www/htdocs | DocumentRoot /www/hdocs ServerName general.dev ServerName general.dev ErrorLog logs/error_log ErrorLog logs/error_log</VirtualHost> </VirtualHost>
  45. 45. RULE 6KEEP ANAUDIT TRAIL
  46. 46. Hot Key Loghttp://www.blacktree.com/http://do.davebsd.com/https://launchpad.net/mbhttp://simplenoteapp.com/
  47. 47. Backpack Journalhttp://backpackit.com/
  48. 48. [root@localhost htdocs]# history 20 365 ls /mnt/hgfs/habari/ 366 ls 367 vi /etc/httpd/conf.d/web.conf 368 setenforce 0 369 /etc/init.d/httpd restart 370 vi /var/log/httpd/error_log 371 cd /mnt/hgfs/habari/ 372 ls 373 cd htdocs/ 374 ls 375 cd scripts/ 376 ls 377 cd .. 378 ls 379 vi /etc/php.ini
  49. 49. RULE 7CHECK THEPLUG
  50. 50. Sources of Plugs[root@localhost ~]# apachectl -MLoaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) [root@localhost ~]# whoami auth_basic_module (shared) root auth_digest_module (shared) [root@localhost ~]# ifconfig authn_file_module (shared) eth0 Link encap:Ethernet HWad authn_alias_module (shared) authn_anon_module inet addr:192.168.192.129 (shared) inet6 addr: fe80::20c:29ff:authn_dbm_module (shared)
  51. 51. RULE 8GET A FRESHVIEW
  52. 52. “Grovelling is nota substitute fordoing yourhomework”- ESRhttp://www.catb.org/esr/faqs/smart-questions.html
  53. 53. RULE 9IF YOU DIDN’TFIX IT -IT AIN’T FIXED
  54. 54. Five Whys The page is blank: Why? There is a fatal error: Why?No mb_check_encoding(): Why? mbstring is not installed: Why? It isn’t part of the build: Why?It was setup for another project.
  55. 55. The Rules1. Understand The System2. Make It Fail3. Quit Thinking And Look4. Divide And Conquer5. Change One Thing At A Time6. Keep An Audit Trail7. Check The Plug8. Get A Fresh View9. If You Didn’t Fix It, It Ain’t Fixed
  56. 56. Questions ?
  57. 57. Image CreditsWhen men were men and wore white coats - by Jitzehttp://www.flickr.com/photos/jitze1942/4292084185/Vacuum Tube Etch-A-Sketch - by Jurvetsonhttp://www.flickr.com/photos/jurvetson/197768962/Classic - by Oskayhttp://www.flickr.com/photos/oskay/1364147095Firmware Bug - by Oskayhttp://www.flickr.com/photos/oskay/1364148351Ready to hop - by Oskayhttp://www.flickr.com/photos/oskay/1364153441/Albino - by Oskayhttp://www.flickr.com/photos/oskay/1364143833Coming Through! - by Oskayhttp://www.flickr.com/photos/oskay/1364147807Tux the Pinguin - by Patrick van der VeldenFrom the photographer’s private collection
  58. 58. THANKANDTOOLSDEBUGGING: RULES YOU http://joind.in/3393

×