Working with the Profiler
The purpose
of this tutorial is to teach you how to profile files and applications
in order to gain maximal efficiency in the execution of your script.
Contents
Purpose and Usage
Zend Profiler detects bottlenecks in scripts by locating problematic
sections of code. These are scripts that consume excessive loading-time.
The Profiler provides you with detailed reports that are essential to
optimizing the overall performance of your application.
Zend Studio
includes five types of profiling:
Locally Profiling PHP Scripts - Profiling PHP files
using Zend Studio's
internal PHP Executable debugger.
Remotely Profiling PHP Scripts - Profiling PHP files
using your server's debugger.
Profiling PHP Web Pages - Profiling files, applications
and projects on your server, using the local or server copies of your
files.
Profiling URLs - Debug applications on your server by
entering a URL.
Toolbar Profiling - Debug files and applications directly
from your browser.
Profiling PHP Scripts
Files can be profiled using either Zend Studio's internal debugger or
your external (remote) server.
Use the remote profiling function if you want to test the execution
of the file on your server's environment. This is especially relevant
if your server's loaded extensions are different to Zend Studio's internal
server.
|
|
|
|

|
The following procedure demonstrates
how to profile a PHP Script, either locally or remotely:
Create a file, called Person,
and copy-paste the example code into it.
(Click
here for the example code)
Create a second file, called
tryPerson, and copy-paste the example code into it. (Click
here for the example code).
Save both files.
Click the arrow next to
the Profile button on the toolbar and select Profile Configurations...
-or- from the main menu go to Run | Profile Configurations... -or- right-click
in PHP Explorer view and select Profile Configurations....
A Profile dialog will appear.

Double-click the PHP Script
option to create a new Profile configuration.
Enter a name for the new
configuration.
To profile the file locally
using Zend Studio's
internal debugger, select the PHP Executable setting under the Debugger
Location category and select the required PHP executable (PHP 4 or 5).
To profile the file remotely on your server using the Zend Debugger
installed on your server, select the PHP Web Server option and select
your server from the drop-down list. (If you have not yet configured a
server, click the PHP Servers link and follow the instructions under Adding PHP Servers.)
Under PHP File, click Browse
and select the "TryPerson" file.
Click Apply and then Profile.
A confirmation dialog will
be displayed asking whether you want to open the Profiling Perspective.
Click Yes. (If you would like the Profiling Perspective to open by
default in the future, mark the 'Remember my decision' checkbox.)
|
|
The Profiling Perspective will open,
displaying the Profiling Monitor window with the following information:
Profiler
Information - provides general information on the profiling duration
and date, number of files constructing the requested URL and more. In
addition, it displays a Time Division Pie Chart for the files in the URL.
The right side displays time division in a pie chart and the left side
provides the following information:
URL - The URL analyzed
Query - The specific query
parameters
Path - The exact location
of the first file called
Total Request Time - Total
process time of the entire page
Number of Files - Number
of files composing the page
Date - Date and time that
the profiling took place

Execution
Statistics - Displays the list of files constructing the URL and
detailed information on functions in the files. The window contains statistics
relevant to each function:
Function - The name and
location of the function.
Calls Count - The number
of times that the function was called.
Average Own Time - The
average duration without internal calls.
Own Time(s) - The net
process duration without internal calls.
Others
Time(s) - Time spent on calling other files.
Total Time(s) - The total
process duration including internal calls.

Note:
Click the 'Show as percentage' button on the toolbar
to see the statistics as percentages rather than times.
Function - Function name
File - The file in which
the function is located
Total
Execution Time - Percent of time taken per function.
Duration
Time - Time taken per function. In milliseconds.

Code Coverage
Summary - Summary of how many lines of code were covered.
Element - The file / folder
that was called.
Covered Lines (Visited
/ Significant / Total) - Percentage of lines covered within each file.
(Visited = Number of lines covered / Significant = number of lines excluding
comments and declarations/ Total = Total number of lines in the file.)

Clicking on the 'Covered lines' percentages
will open an editor containing the debug file, with the covered lines
highlighted:

|
Back to Top
Profiling PHP Web Pages
Zend Studio
also allows you to profile whole applications, projects or collections
of files that are already on the server.
|
|
|
|

|
The following steps demonstrate how to profile
a file on an external server:
Create a file, called Person,
and copy-paste the example code into it.
(Click
here for the example code).
Create a second file, called
tryPerson, and copy-paste the example code into it. (Click
here for the example code).
Save both files.
Copy them to your server.
Click the arrow next to
the Profile button on the toolbar and select Profile
Configurations... –or- right-click the file in PHP explorer or within
the file's editor window and select Profile As | Open Debug dialog.
A Profile dialog will appear.
Double-click on the PHP
Web Page option to create a new profile configuration.
Enter a name for the new
configuration.
Select the Zend Debugger
to from the Server Debugger drop-down list.
Ensure that your server
is selected from the list.
If you have not configured a server, click New and enter:
Your server's
name.
The URL
of its document root.
Under the File/Project category,
click Browse and select the "tryPerson" file. This will be the
file from which the profiling process will start.
Click Apply and then Profile.
A confirmation dialog will be displayed asking whether you want to
open the Profiling Perspective.
Click Yes. (If you would
like the Profiling Perspective to open by default in the future, mark
the 'Remember my decision' checkbox.)
|
|
The Profiling Perspective will open, displaying the Profiling Monitor
window with profiling information.
See PHP Perspectives and Views
for details on the information displayed in the profiling perspective. |
Back to Top