|
|
1 |
PHP Quick Profiler README |
|
|
2 |
http://particletree.com/features/php-quick-profiler/ |
|
|
3 |
|
|
|
4 |
#### On This Page #### |
|
|
5 |
|
|
|
6 |
1. Introduction and Overview of Files |
|
|
7 |
2. Getting the Example Working |
|
|
8 |
3. Setting up the Database Class |
|
|
9 |
4. Using Smarty instead of PHP echos |
|
|
10 |
|
|
|
11 |
##################################### |
|
|
12 |
1. Introduction and Overview of Files |
|
|
13 |
##################################### |
|
|
14 |
|
|
|
15 |
PHP Quick Profiler is a helper class that outputs debugging related information |
|
|
16 |
to the screen when the page has finished executing. This zip package contains a |
|
|
17 |
functional example project that utilizes the helper classes. |
|
|
18 |
|
|
|
19 |
- index.php : The landing page of the example. Navigate to it in your browser to see the demo. |
|
|
20 |
- display.php : Contains the markup for PQP. |
|
|
21 |
- pqp.tpl : A Smarty variation of the PQP markup. |
|
|
22 |
- /css/ : The stylesheets used by PQP. |
|
|
23 |
- /images/ : The images used by PQP. |
|
|
24 |
- /classes/Console.php : The class used to log items to the PQP display. |
|
|
25 |
- /classes/MySqlDatabase : A sample database wrapper to explain how database logging could be implemented. |
|
|
26 |
- /classes/PhpQuickProfiler : The core class that compiles the data before outputting to the browser. |
|
|
27 |
|
|
|
28 |
############################## |
|
|
29 |
2. Getting the Example Working |
|
|
30 |
############################## |
|
|
31 |
|
|
|
32 |
For the most part, the example will work once you drop it in your root directory. |
|
|
33 |
There are a few settings to check though. |
|
|
34 |
|
|
|
35 |
- In PHPQuickProfiler.php, set the $config member variable to the path relative to your root (located in the constructor). |
|
|
36 |
- If PQP does not appear after navigating to index.php in your browser, locate the destructor |
|
|
37 |
of the PQPExample class (at the bottom). Rename the function from __destruct() to display(). Then, |
|
|
38 |
manually call the function display() just underneath the class after the call to init(). The reason this would |
|
|
39 |
happen is because the destructor is not firing on your server configuration. |
|
|
40 |
- At this point, everything should work except for the database tab. |
|
|
41 |
|
|
|
42 |
################################ |
|
|
43 |
3. Setting up the Database Class |
|
|
44 |
################################ |
|
|
45 |
|
|
|
46 |
NOTE - This step does require knowledge on PHP / Database interactions. There is no copy/paste solution. |
|
|
47 |
|
|
|
48 |
Logging database data is by far the hardest part of integrating PQP into your own project. It |
|
|
49 |
requires that you have some sort of database wrapper around your code. If you do, it should be easy to implement. |
|
|
50 |
To show you how it works, follow these steps with the sample database class we have provided. |
|
|
51 |
|
|
|
52 |
- Create a database named 'test' and run the following query on it. |
|
|
53 |
|
|
|
54 |
CREATE TABLE `Posts` ( |
|
|
55 |
`PostId` int(11) unsigned NOT NULL default '0', |
|
|
56 |
PRIMARY KEY (`PostId`) |
|
|
57 |
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
|
|
58 |
|
|
|
59 |
- In index.php, uncomment out the second include, which includes the database class. |
|
|
60 |
- In index.php, uncomment out the function sampleDatabaseData(). |
|
|
61 |
- In the sampleDatabaseData(), supply your database host, username, password, and database name. |
|
|
62 |
|
|
|
63 |
Given those steps, database logging will be enabled. If you would like to transition this to your own database class, |
|
|
64 |
open /classes/MySqlDatabase.php and note the following: |
|
|
65 |
|
|
|
66 |
- $queryCount and $queries member variables declared on initialization |
|
|
67 |
- When a query is run, the following is executed: |
|
|
68 |
|
|
|
69 |
$start = $this->getTime(); |
|
|
70 |
$rs = mysql_query($sql, $this->conn); |
|
|
71 |
$this->queryCount += 1; |
|
|
72 |
$this->logQuery($sql, $start); |
|
|
73 |
|
|
|
74 |
- Everything in /classes/MySqlDatabase.php under the section comment "Debugging" |
|
|
75 |
must be available for the above snippet to work. |
|
|
76 |
|
|
|
77 |
#################################### |
|
|
78 |
4. Using Smarty instead of PHP echos |
|
|
79 |
#################################### |
|
|
80 |
|
|
|
81 |
We love Smarty and hate echos, but to make this work for everyone we set the default as echos. To show love |
|
|
82 |
to the Smarty users out there, we have included a pqp.tpl file for PQP. To make it work, you would have to change |
|
|
83 |
the following in /classes/PhpQuickProfiler.php: |
|
|
84 |
|
|
|
85 |
- Add a require_once to your Smarty Library. |
|
|
86 |
- In the constructor, declare an instance of Smarty: $this->smarty = new Smarty(...); |
|
|
87 |
- Everywhere in in the code you see $this->output[... change it to a smarty assign. For example: |
|
|
88 |
|
|
|
89 |
$this->output['logs'] = $logs; |
|
|
90 |
|
|
|
91 |
... becomes ... |
|
|
92 |
|
|
|
93 |
$this->smarty->assign('logs', $logs); |
|
|
94 |
|
|
|
95 |
After doing it once, you'll see the pattern and can probably use a find/replace to do the rest quickly. |
|
|
96 |
|
|
|
97 |
- Locate the display() function at the bottom. Remove the last 2 lines, and add: |
|
|
98 |
|
|
|
99 |
$this->smarty->display('pathToDisplay.tpl'); |
|
|
100 |
|
|
|
101 |
All set after that! |
|
|
102 |
|