These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - |
||
4 | |||
5 | Title : Sample Landing page for PHP Quick Profiler Class |
||
6 | Author : Created by Ryan Campbell |
||
7 | URL : http://particletree.com/features/php-quick-profiler/ |
||
8 | |||
9 | Last Updated : April 22, 2009 |
||
10 | |||
11 | Description : This file contains the basic class shell needed |
||
12 | to use PQP. In addition, the init() function calls for example |
||
13 | usages of how PQP can aid debugging. See README file for help |
||
14 | setting this example up. |
||
15 | |||
16 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ |
||
17 | |||
18 | //require_once('classes/PhpQuickProfiler.php'); |
||
19 | |||
20 | class PQPExample { |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
21 | |||
22 | private $profiler; |
||
23 | |||
24 | public function __construct() { |
||
25 | $this->profiler = new ParticleTree\Pqp\PhpQuickProfiler(PhpQuickProfiler::getMicroTime()); |
||
26 | } |
||
27 | |||
28 | public function init() { |
||
29 | $this->sampleConsoleData(); |
||
30 | $this->sampleDatabaseData(); |
||
0 ignored issues
–
show
The method
sampleDatabaseData() does not seem to exist on object<PQPExample> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
31 | $this->sampleMemoryLeak(); |
||
32 | $this->sampleSpeedComparison(); |
||
33 | } |
||
34 | |||
35 | /*------------------------------------------- |
||
36 | EXAMPLES OF THE 4 CONSOLE FUNCTIONS |
||
37 | -------------------------------------------*/ |
||
38 | |||
39 | public function sampleConsoleData() { |
||
40 | try { |
||
41 | Console::log('Begin logging data'); |
||
42 | Console::logMemory($this, 'PQP Example Class : Line '.__LINE__); |
||
43 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
44 | Console::log(array('Name' => 'Ryan', 'Last' => 'Campbell')); |
||
45 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
46 | Console::logMemory($this, 'PQP Example Class : Line '.__LINE__); |
||
47 | Console::log('Ending log below with a sample error.'); |
||
48 | throw new Exception('Unable to write to log!'); |
||
49 | } |
||
50 | catch(Exception $e) { |
||
51 | Console::logError($e, 'Sample error logging.'); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | |||
56 | /*----------------------------------- |
||
57 | EXAMPLE MEMORY LEAK DETECTED |
||
58 | ------------------------------------*/ |
||
59 | |||
60 | public function sampleMemoryLeak() { |
||
61 | $ret = ''; |
||
62 | $longString = 'This is a really long string that when appended with the . symbol |
||
63 | will cause memory to be duplicated in order to create the new string.'; |
||
64 | for($i = 0; $i < 10; $i++) { |
||
65 | $ret = $ret . $longString; |
||
66 | Console::logMemory($ret, 'Watch memory leak -- iteration '.$i); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | /*----------------------------------- |
||
71 | POINT IN TIME SPEED MARKS |
||
72 | ------------------------------------*/ |
||
73 | |||
74 | public function sampleSpeedComparison() { |
||
75 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
76 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
77 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
78 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
79 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
80 | Console::logSpeed('Time taken to get to line '.__LINE__); |
||
81 | } |
||
82 | |||
83 | } |
||
84 | |||
85 | $pqp = new PQPExample(); |
||
86 | $pqp->init(); |
||
87 | |||
88 | ?> |
||
89 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||
90 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||
91 | |||
92 | <html xmlns="http://www.w3.org/1999/xhtml"> |
||
93 | <head> |
||
94 | |||
95 | <title> |
||
96 | PHP Quick Profiler Demo |
||
97 | </title> |
||
98 | |||
99 | |||
100 | <!-- CSS --> |
||
101 | |||
102 | <style type="text/css"> |
||
103 | body{ |
||
104 | font-family:"Lucida Grande", Tahoma, Arial, sans-serif; |
||
105 | margin:100px 0 0 0; |
||
106 | background:#eee; |
||
107 | } |
||
108 | h3{ |
||
109 | line-height:160%; |
||
110 | } |
||
111 | #box{ |
||
112 | margin:100px auto 0 auto; |
||
113 | width: 450px; |
||
114 | padding:10px 20px 30px 20px; |
||
115 | background-color: #FFF; |
||
116 | border: 10px solid #dedede; |
||
117 | } |
||
118 | #box ul { |
||
119 | margin:0 0 20px 0; |
||
120 | padding:0; |
||
121 | } |
||
122 | #box li { |
||
123 | margin:0 0 0 20px; |
||
124 | padding:0 0 10px 0; |
||
125 | } |
||
126 | li a{ |
||
127 | color:blue; |
||
128 | } |
||
129 | strong a{ |
||
130 | color:#7EA411; |
||
131 | } |
||
132 | </style> |
||
133 | |||
134 | <body> |
||
135 | |||
136 | <div id="box"> |
||
137 | <h3>On this Page You Can See How to <br /> Use the PHP Quick Profiler to...</h3> |
||
138 | |||
139 | <ul> |
||
140 | <li>Log PHP Objects. [ <a href="#" onclick="changeTab('console'); return false;">Demo</a> ]</li> |
||
141 | <li>Watch as a string eats up memory. [ <a href="#" onclick="changeTab('memory'); return false;">Demo</a> ]</li> |
||
142 | <li>Monitor our queries and their indexes. [ <a href="#" onclick="changeTab('queries'); return false;">Demo</a> ]</li> |
||
143 | <li>Ensure page execution time is acceptable. [ <a href="#" onclick="changeTab('speed'); return false;">Demo</a> ]</li> |
||
144 | <li>Prevent files from getting out of control. [ <a href="#" onclick="changeTab('files'); return false;">Demo</a> ]</li> |
||
145 | </ul> |
||
146 | |||
147 | <strong>Return to <a href="http://particletree.com/features/php-quick-profiler/">Particletree</a>.</strong> |
||
148 | </div> |
||
149 | |||
150 | </body> |
||
151 | </html> |
||
152 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.