Completed
Push — master ( 77243d...dac2cf )
by Jacob
02:14
created

index.php (4 issues)

Upgrade to new PHP Analysis Engine

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
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 112.

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.

Loading history...
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');
0 ignored issues
show
Unused Code Comprehensibility introduced by
91% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
19
//require_once('classes/MySqlDatabase.php');
20
21
class PQPExample {
0 ignored issues
show
Coding Style Compatibility introduced by
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.

Loading history...
22
	
23
	private $profiler;
24
	private $db = '';
25
	
26
	public function __construct() {
27
		$this->profiler = new ParticleTree\Pqp\PhpQuickProfiler(PhpQuickProfiler::getMicroTime());
28
	}
29
	
30
	public function init() {
31
		$this->sampleConsoleData();
32
		$this->sampleDatabaseData();
33
		$this->sampleMemoryLeak();
34
		$this->sampleSpeedComparison();
35
	}
36
	
37
	/*-------------------------------------------
38
	     EXAMPLES OF THE 4 CONSOLE FUNCTIONS
39
	-------------------------------------------*/
40
	
41
	public function sampleConsoleData() {
42
		try {
43
			Console::log('Begin logging data');
44
			Console::logMemory($this, 'PQP Example Class : Line '.__LINE__);
45
			Console::logSpeed('Time taken to get to line '.__LINE__);
46
			Console::log(array('Name' => 'Ryan', 'Last' => 'Campbell'));
47
			Console::logSpeed('Time taken to get to line '.__LINE__);
48
			Console::logMemory($this, 'PQP Example Class : Line '.__LINE__);
49
			Console::log('Ending log below with a sample error.');
50
			throw new Exception('Unable to write to log!');
51
		}
52
		catch(Exception $e) {
53
			Console::logError($e, 'Sample error logging.');
54
		}
55
	}
56
	
57
	/*-------------------------------------
58
	     DATABASE OBJECT TO LOG QUERIES
59
	--------------------------------------*/
60
	
61
	public function sampleDatabaseData() {
62
		/*$this->db = new ParticleTree\Pqp\MySqlDatabase(
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
			'your DB host', 
64
			'your DB user',
65
			'your DB password');
66
		$this->db->connect(true);
67
		$this->db->changeDatabase('your db name');
68
		
69
		$sql = 'SELECT PostId FROM Posts WHERE PostId > 2';
70
		$rs = $this->db->query($sql);
71
		
72
		$sql = 'SELECT COUNT(PostId) FROM Posts';
73
		$rs = $this->db->query($sql);
74
		
75
		$sql = 'SELECT COUNT(PostId) FROM Posts WHERE PostId != 1';
76
		$rs = $this->db->query($sql);*/
77
	}
78
	
79
	/*-----------------------------------
80
	     EXAMPLE MEMORY LEAK DETECTED
81
	------------------------------------*/
82
	
83
	public function sampleMemoryLeak() {
84
		$ret = '';
85
		$longString = 'This is a really long string that when appended with the . symbol 
86
					  will cause memory to be duplicated in order to create the new string.';
87
		for($i = 0; $i < 10; $i++) {
88
			$ret = $ret . $longString;
89
			Console::logMemory($ret, 'Watch memory leak -- iteration '.$i);
90
		}
91
	}
92
	
93
	/*-----------------------------------
94
	     POINT IN TIME SPEED MARKS
95
	------------------------------------*/
96
	
97
	public function sampleSpeedComparison() {
98
		Console::logSpeed('Time taken to get to line '.__LINE__);
99
		Console::logSpeed('Time taken to get to line '.__LINE__);
100
		Console::logSpeed('Time taken to get to line '.__LINE__);
101
		Console::logSpeed('Time taken to get to line '.__LINE__);
102
		Console::logSpeed('Time taken to get to line '.__LINE__);
103
		Console::logSpeed('Time taken to get to line '.__LINE__);
104
	}
105
	
106
	public function __destruct() {
107
		$this->profiler->display($this->db);
108
	}
109
	
110
}
111
112
$pqp = new PQPExample();
113
$pqp->init();
114
115
?>
116
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
117
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
118
119
<html xmlns="http://www.w3.org/1999/xhtml">
120
<head>
121
122
<title>
123
PHP Quick Profiler Demo
124
</title>
125
126
127
<!-- CSS -->
128
129
<style type="text/css">
130
body{
131
	font-family:"Lucida Grande", Tahoma, Arial, sans-serif;
132
	margin:100px 0 0 0;
133
	background:#eee;
134
}
135
h3{
136
	line-height:160%;
137
}
138
#box{
139
	margin:100px auto 0 auto;
140
	width: 450px;
141
	padding:10px 20px 30px 20px;
142
	background-color: #FFF;
143
	border: 10px solid #dedede;
144
}
145
#box ul {
146
	margin:0 0 20px 0;
147
	padding:0;
148
}
149
#box li {
150
	margin:0 0 0 20px;
151
	padding:0 0 10px 0;
152
}
153
li a{
154
	color:blue;
155
}
156
strong a{
157
	color:#7EA411;
158
}
159
</style>
160
161
<body>
162
163
<div id="box">
164
	<h3>On this Page You Can See How to <br /> Use the PHP Quick Profiler to...</h3>
165
166
	<ul>
167
	<li>Log PHP Objects. [ <a href="#" onclick="changeTab('console'); return false;">Demo</a> ]</li>
168
	<li>Watch as a string eats up memory. [ <a href="#" onclick="changeTab('memory'); return false;">Demo</a> ]</li>
169
	<li>Monitor our queries and their indexes. [ <a href="#" onclick="changeTab('queries'); return false;">Demo</a> ]</li>
170
	<li>Ensure page execution time is acceptable. [ <a href="#" onclick="changeTab('speed'); return false;">Demo</a> ]</li>
171
	<li>Prevent files from getting out of control. [ <a href="#" onclick="changeTab('files'); return false;">Demo</a> ]</li>
172
	</ul>
173
	
174
	<strong>Return to <a href="http://particletree.com/features/php-quick-profiler/">Particletree</a>.</strong>
175
</div>
176
177
</body>
178
</html>
179