PHP Page generation time
Posted on: April 14, 2006 at 12:00 AM
This page was generated in X minutes. If you have seen these messages you probably would like to learn how to implement them.

PHP Page generation time

In this tutorial I'll show you how to capture execution time in PHP. I bet you already have seen somewhere in the net something like:

Page generated in 0.325261 seconds

you can do it quickly with just 3 functions:

1) Function
string microtime(void)
Returns string containing two parts "msec sec",
where msec - number of microseconds
and sec - current time in seconds in timestamp format from the UNIX Epoch (0:00:00 January 1, 1970 GMT)
This function works only with operation systems supporting gettimeofday() system call.

2) Function
array explode(string separator, string string [, int limit])
This one splits source string into parts by separator and fills resulting array with all parts (or as many as specified in limit).

3) Function
void printf (string format [, mixed args])
This is completely similar to C language printf function. It will output args values by text format, specified in format argument.
Arguments:
format - text format to apply for output
args - values inserted into format

Now let's think about the logic of our task.
What do we need to do ?
First we have to get current time before code is executed. Then we will have to get current time again after the code. And at last we need to print the difference between start and end time values.

Before your main PHP code write:

//Get current time
    $mtime = microtime();
//Split seconds and microseconds
    $mtime = explode(" ",$mtime);
//Create one value for start time
    $mtime = $mtime[1] + $mtime[0];
//Write start time into a variable
    $tstart = $mtime;


Now, go to the end of your main PHP code and write after all:

//Get current time as we did at start
    $mtime = microtime();
    $mtime = explode(" ",$mtime);
    $mtime = $mtime[1] + $mtime[0];
//Store end time in a variable
    $tend = $mtime;
//Calculate the difference
    $totaltime = ($tend - $tstart);
//Output result
    printf ("Page was generated in %f seconds !", $totaltime);


Please note, that we can't use simple output (print or echo functions), cause the value we output is of the double precision type and we should specify how to output it correctly.
More Tutorials on roseindia.net for the topic PHP Page generation time.
PHP Page generation time
PHP Page generation time In this tutorial I'll show you how to capture execution time in PHP. I bet you already have seen somewhere in the net something... and end time values. Before your main PHP code write: //Get current time
 
Time table generation
Time table generation  Hi I am 3rd year bca student i want create time table generator for my project.i am going to create it as school time table... informations we have to provide to generate time table? pls make me clear. Thanks
 
How to convert date to time in PHP?
google search and found some PHP Date time scripts listed on the page. Glad...How to convert date to time in PHP?  Hi, programmer. The PHP... and time. The PHP "time()" function is used to get the current Unix timestamp
 
Page Loading Time
on this issue. I saw something done in PHP at this link http://www.roseindia.net/php/Page...Page Loading Time  I have a application which has a tab type..., a page opens(ajax calls to server) which has atleast two iframes in it. I want
 
Time table generation
Time table generation  Hi I am 3rd year bca student i want create time table generator for my project.i am going to create it as school time table management.i want some ideas related this project I mean i want
 
PHP Display date and time
PHP displaying the time and date into your timezone  ...() function in PHP, it doesn't display the correct time and date for their region... web page: http://www.roseindia.net/tutorial/php/phpdate/index.htmlADS
 
PHP Make Time
PHP  Make Time In PHP, mktime() funtion is used for doing date arithmetic... visit our web page http://www.roseindia.net/tutorial/php/examples... This parameter is set to either of these values: 1 if the time is during
 
pdf generation.
pdf generation.  i want to generate the data which is stored in mysql data base in pdf format with php. how i will do
 
php parse string to time
php parse string to time  I am looking for a solution to parse a string into a formatted date time string
 
PHP Variables from Page to Page
PHP Variables from Page to Page A PHP programmer can easily pass the variables...[] function in php is used to take the information from one page to another page...[] function in php is also used to take the information from one page to another page
 
time
time format hh:mm:ss  Hi. I have retrieved time from mysql database...?   Here is a jsp example that fetch the time from the database and display in different format. <%@page import="java.sql.*"%> <%@page import
 
time
time display only as hh:mm.  Hi. I have retrieved time from mysql...?   Here is a jsp example that fetch the time from the database and display in different format. <%@page import="java.sql.*"%> <%@page
 
time
time  Hi. I have retrieved time from mysql database. its in th format... is a jsp example that fetch the time from the database and display in different format. <%@page import="java.sql.*"%> <%@page import="java.util.*"%>
 
time
time  Hi. I have retrieved time from mysql database. its in th format... is a jsp example that fetch the time from the database and display in different format. <%@page import="java.sql.*"%> <%@page import="java.util.*"%>
 
time
retrieved time from mysql database  Hi. I have retrieved time from.... wat to do?   Here is a jsp example that fetch the time from the database and display in different format. <%@page import="java.sql.*"%> <
 
time ()
PHP time() Function The time() returns the current time  measured...;). Syntax of time() Function in PHP time(void) Parameter of time() Function in PHP void - void is optional parameter.  Example of time
 
php
php  plz tell me code for PHP SQL Insert,delete,update,view is used to insert the record from HTML page to Mysql database using in single PHP form
 
Sitemap PHP Tutorial
PHP | PHP Cookies | File Manipulation in PHP | PHP displaying the time and date into your timezone | PHP Examples | Advance PHP MySQL | PHP Page Loading Time | PHP Date Time Zone | PHP ini | PHP variables | PHP
 
php page caching
php page caching  Page caching in PHP script required
 
id generation
--%> <%@ page language="java" import="java.util.*" pageEncoding...; <meta http-equiv="description" content="This is my page"> <...; </body> </html> 2) <%-- insert.jsp--%> <%@ page
 
PHP Previous Next Page - PHP
PHP Previous Next Page  PHP Previous Next PageIs it possible to create dynamic navigation using PHP and MYSQL? DO I need to create a class to create the next, previous buttons in PHP? I?m digging for a small as well as handy code
 
linking php page to other php pages
linking php page to other php pages  How to link the PHP Page to other PHP page
 
Best PHP tutorial for beginners
) Learn basics and advanced concepts of PHP programming language in very less time... PHP from beginning. PHP Tutorial index page. You find good tutorials... MySQL Tutorial index page. Above tutorials will help you in learning PHP from
 
php web page capture
php web page capture  How to capture the history of a web page using PHP
 
PHP Generate a pages loading time Tutorial
PHP Page Loading Time      ... of time taken to load and display a specific page, for debugging or display purposes. To get the loading time of your page just put the following code at the top
 
login page in php
login page in php  How to create a login page in php
 
PHP Date and Time Functions
The PHP Date and Time Functions functions allows the developer to read... of the examples of PHP Date and Time Functions.ADS_TO_REPLACE_1 Printing amount of seconds passed since January 1 1970 00:00:00 GMT: <?php print time(); ?> Printing
 
The PHP Date() Function
The PHP Date() Function The PHP date() function is used for formatting the date and time. It formats a timestamp (a sequence of characters representing the date and/or time at which a certain event occurred) to make more readable
 
PHP Date and Time
PHP Date and Time The PHP Date and Time function is massively used... the functions of the software. ADS_TO_REPLACE_1 The PHP date and Time functions allow you to access the date and time from the server where your PHP scripts
 
How to Increase Script Execution Time Limit in php ?
How to Increase Script Execution Time Limit in php ?   Increase Script Execution Time Limit in php configuration   Sometimes you need to execute a large php script. Because of PHPâ??s default execution time settings
 
maximum execution time of 30 seconds exceeded in php
maximum execution time of 30 seconds exceeded in php  My PHP program is taking long time to run it is giving following error: Maximum execution time of 30 seconds exceeded in php file How to resolve this issue? Thanks
 
Open Source PHP
; Calling PHP file / HTML page is very clean. All that is required is creating...Open Source PHP Open-source PHP framework AjaxAC is an open-source framework written in PHP, used to develop/create/generate AJAX applications
 
PHP Date and Time
 The PHP Date and Time functions are very useful in manipulating the Date in your PHP program. The PHP Date and Time generates the current date and time... also use the following code to print the long string of the time: Current
 
QuTags - PHP Style AJAX
QuTags - PHP Style AJAX       PHP & C Module that is AJAX for PHP, with no JAX. You don't even have... or AJAX; just PHP is enough. Simply, QuTags maximize application performance
 
PHP Introduction
and takes less time to master. PHP Introduction The word PHP stands... into HTML page. PHP allows the developers to add the dynamic processing logic to HTML...In this section I will introduce you with the PHP scripting language. The PHP
 
custom 404 error page php - PHP
custom 404 error page php  What is this error means: custom 404 error page php
 
Hibernate generation Id to postgreSQL
Hibernate generation Id to postgreSQL  Hi, I'm trying to implement a id generator in Hibernate, but I'm having a problem. Hibernate doesn't seems..._description 1|john 2|mike 3|Peter 2 - Now, I clean the table, and next time I
 
PHP Random Number
PHP Generate Random Numbers: A random number is becoming more useful.... To generate random number, PHP provides rand() function. ..._TO_REPLACE_1 <?php echo "<b>rand() function
 
jsp code for dynamic time table generation - JSP-Servlet
jsp code for dynamic time table generation  hi I am doing my academic project college automation. I want to generate time table dynamically for each btech and mca,mba branches.Pls provide a solution how to process
 
login page php mysql example
login page php mysql example  How to create a login page for user in PHP Mysql? Please provide me a complete tutorial. Thanks in Advance
 
PHP Frameworks
of fetching data from PHP into a web page which has already loaded, without...;  DutchPIPE PHP object-oriented framework to turn sites into real-time... PHP Frameworks      
 
Display PHP clock with user input date and time
Display PHP clock with user input date and time  The following PHP code displays a clock with current date and time. I want the clock to receive user input date and time. How can this be done? <?php date<em>
 
What is a PHP File?
page and may have an extension of .php. The earlier version used the .php3...A PHP file includes PHP code, functions, text HTML tags and scripts that can process online forms, get the date and time, or access information from
 
What is the default session time in php and how can I change it?
What is the default session time in php and how can I change it?  What is the default session time in php and how can I change
 
How can we increase the execution time of a php script?
How can we increase the execution time of a php script?  How can we increase the execution time of a php script
 
PHP Get Average - PHP
PHP Get Average  I am writing a method to calculate the average... in PHP. In my code, we are providing maximum four options to the user to rate. Only one answer can be selected at a time
 
how to set time in jsp page
how to set time in jsp page   I need code for set the time in jsp code .iam using struts frame work back end oracle 10g ide is eclipse 6.0
 
PHP Date and Time Date and time Tutorial
Date and time Learn how to use PHP Date and Time functions To get formatted date and time value you can use date() function. It is very easy to pass any format you want to get formatted time output. string date(string format, int
 
PHP vs J2EE, PHP vs JAVA
overhead on server communication to PHP code. In PHP architecture the PHP page...PHP Vs Java Those who think that java scales and PHP not is wrong, PHP... is easy-to-write, easy-maintain, cross-platform, scalable PHP platform
 
PHP Tutorials from RoseIndia
;   PHP Page Loading Time... document) using this tutorial   PHP displaying the time and date into your....   PHP Date Time Zone In PHP Date Time Zone class displays the time
 
Ads

Related Tags for PHP Page generation time:


Ads

 
Advertisement null

Ads