Add analytics
[bus.git] / busui / owa / includes / pqp / index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
 
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 Title : Sample Landing page for PHP Quick Profiler Class
 Author : Created by Ryan Campbell
 URL : http://particletree.com/features/php-quick-profiler/
 
 Last Updated : April 22, 2009
 
 Description : This file contains the basic class shell needed
 to use PQP. In addition, the init() function calls for example
 usages of how PQP can aid debugging. See README file for help
 setting this example up.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
require_once('classes/PhpQuickProfiler.php');
//require_once('classes/MySqlDatabase.php');
 
class PQPExample {
        
        private $profiler;
        private $db = '';
        
        public function __construct() {
                $this->profiler = new PhpQuickProfiler(PhpQuickProfiler::getMicroTime());
        }
        
        public function init() {
                $this->sampleConsoleData();
                $this->sampleDatabaseData();
                $this->sampleMemoryLeak();
                $this->sampleSpeedComparison();
        }
        
        /*-------------------------------------------
             EXAMPLES OF THE 4 CONSOLE FUNCTIONS
        -------------------------------------------*/
        
        public function sampleConsoleData() {
                try {
                        Console::log('Begin logging data');
                        Console::logMemory($this, 'PQP Example Class : Line '.__LINE__);
                        Console::logSpeed('Time taken to get to line '.__LINE__);
                        Console::log(array('Name' => 'Ryan', 'Last' => 'Campbell'));
                        Console::logSpeed('Time taken to get to line '.__LINE__);
                        Console::logMemory($this, 'PQP Example Class : Line '.__LINE__);
                        Console::log('Ending log below with a sample error.');
                        throw new Exception('Unable to write to log!');
                }
                catch(Exception $e) {
                        Console::logError($e, 'Sample error logging.');
                }
        }
        
        /*-------------------------------------
             DATABASE OBJECT TO LOG QUERIES
        --------------------------------------*/
        
        public function sampleDatabaseData() {
                /*$this->db = new MySqlDatabase(
                        'your DB host', 
                        'your DB user',
                        'your DB password');
                $this->db->connect(true);
                $this->db->changeDatabase('your db name');
                
                $sql = 'SELECT PostId FROM Posts WHERE PostId > 2';
                $rs = $this->db->query($sql);
                
                $sql = 'SELECT COUNT(PostId) FROM Posts';
                $rs = $this->db->query($sql);
                
                $sql = 'SELECT COUNT(PostId) FROM Posts WHERE PostId != 1';
                $rs = $this->db->query($sql);*/
        }
        
        /*-----------------------------------
             EXAMPLE MEMORY LEAK DETECTED
        ------------------------------------*/
        
        public function sampleMemoryLeak() {
                $ret = '';
                $longString = 'This is a really long string that when appended with the . symbol 
                                          will cause memory to be duplicated in order to create the new string.';
                for($i = 0; $i < 10; $i++) {
                        $ret = $ret . $longString;
                        Console::logMemory($ret, 'Watch memory leak -- iteration '.$i);
                }
        }
        
        /*-----------------------------------
             POINT IN TIME SPEED MARKS
        ------------------------------------*/
        
        public function sampleSpeedComparison() {
                Console::logSpeed('Time taken to get to line '.__LINE__);
                Console::logSpeed('Time taken to get to line '.__LINE__);
                Console::logSpeed('Time taken to get to line '.__LINE__);
                Console::logSpeed('Time taken to get to line '.__LINE__);
                Console::logSpeed('Time taken to get to line '.__LINE__);
                Console::logSpeed('Time taken to get to line '.__LINE__);
        }
        
        public function __destruct() {
                $this->profiler->display($this->db);
        }
        
}
 
$pqp = new PQPExample();
$pqp->init();
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
<title>
PHP Quick Profiler Demo
</title>
 
 
<!-- CSS -->
 
<style type="text/css">
body{
        font-family:"Lucida Grande", Tahoma, Arial, sans-serif;
        margin:100px 0 0 0;
        background:#eee;
}
h3{
        line-height:160%;
}
#box{
        margin:100px auto 0 auto;
        width: 450px;
        padding:10px 20px 30px 20px;
        background-color: #FFF;
        border: 10px solid #dedede;
}
#box ul {
        margin:0 0 20px 0;
        padding:0;
}
#box li {
        margin:0 0 0 20px;
        padding:0 0 10px 0;
}
li a{
        color:blue;
}
strong a{
        color:#7EA411;
}
</style>
 
<body>
 
<div id="box">
        <h3>On this Page You Can See How to <br /> Use the PHP Quick Profiler to...</h3>
 
        <ul>
        <li>Log PHP Objects. [ <a href="#" onclick="changeTab('console'); return false;">Demo</a> ]</li>
        <li>Watch as a string eats up memory. [ <a href="#" onclick="changeTab('memory'); return false;">Demo</a> ]</li>
        <li>Monitor our queries and their indexes. [ <a href="#" onclick="changeTab('queries'); return false;">Demo</a> ]</li>
        <li>Ensure page execution time is acceptable. [ <a href="#" onclick="changeTab('speed'); return false;">Demo</a> ]</li>
        <li>Prevent files from getting out of control. [ <a href="#" onclick="changeTab('files'); return false;">Demo</a> ]</li>
        </ul>
        
        <strong>Return to <a href="http://particletree.com/features/php-quick-profiler/">Particletree</a>.</strong>
</div>
 
</body>
</html>