Finding and fixing bugs is a major chunk of any developers time. This talk describes the basic rules for effective debugging in any language, but shows how the tools available in PHP can be used to find and fix even the most elusive error
6. Bug
Wiki Tracker Frame
work
RTFM PHP
Doc
php.net
7. $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.');
}
8. Komodo
Eclipse Zend
Studio
TOOLS
PHP Net
Storm Text Beans
Mate
14. 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"));
}
}
29. Zend Drupal
Log syslog
sfLogger
Kohana
Log
error_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);
30. MQ Syslog File
LOGGING
SYSTEM
Gearman Database Pipe
44. [root@localhost ~]# { echo -ne "HTTP/1.0 200 OKrn
rn"; cat test.html; } | nc -l 8080
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
Accept: */*
[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) port
8080 (#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
45. local log_file = 'mysql.log'
local 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()
end
end
MySQL Proxy
47. [root@localhost ~]#: svn st
M index.php
[root@localhost ~]#: git stash save
Saved working directory and index state WIP
on master: 0e22fdd Initial checkin
HEAD is now at 0e22fdd Initial checkin
[root@localhost ~]#: git status
# On branch master
nothing to commit (working directory clean)
Source Control
48. [root@localhost ~]#: svn log .
-------------------------------------------
r4341 | rickc | 2010-09-24 03:01 | 3 lines
Don't test if Post::tags is empty before
getting tags. There may be a performance
hit for this. It can be dealt with if it is
noticable. Fixes ticket #1235. Props to ilo
for 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
53. [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
63. 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.
64. The Rules
1. Understand The System
2. Make It Fail
3. Quit Thinking And Look
4. Divide And Conquer
5. Change One Thing At A Time
6. Keep An Audit Trail
7. Check The Plug
8. Get A Fresh View
9. If You Didn’t Fix It, It Ain’t Fixed
66. Image Credits
When men were men and wore white coats - by Jitze
http://www.flickr.com/photos/jitze1942/4292084185/
Vacuum Tube Etch-A-Sketch - by Jurvetson
http://www.flickr.com/photos/jurvetson/197768962/
Classic - by Oskay
http://www.flickr.com/photos/oskay/1364147095
Firmware Bug - by Oskay
http://www.flickr.com/photos/oskay/1364148351
Ready to hop - by Oskay
http://www.flickr.com/photos/oskay/1364153441/
Albino - by Oskay
http://www.flickr.com/photos/oskay/1364143833
Coming Through! - by Oskay
http://www.flickr.com/photos/oskay/1364147807
Tux the Pinguin - by Patrick van der Velden
From the photographer’s private collection