PHP: the script execution time in practice


2018-03-17 19:55:16




1Like 0Dislike


PHP script execution time is important for the purpose of determining the time of a page or element to building a safe and robust code in General.

php script execution time

There are three fundamentally different options for this goal: the formation of the entire page, the updated page element and the execution time is not limited, including the fact of the termination of the session by the visitor.

Execution Time of the script

The PHP script execution time to determine just like it was done on the first programming languages. Identifying the time stamps at the beginning and at the end of the sample code by calculating the difference of these values, you can determine exactly how much time did execution of all syntactic constructions that are between the initial and final markers.

A Simple script: example of determining the execution time of the loop.

Author's example is not a picture

PHP provides developers with two function: microtime() and time () that can be used to generate timestamps. Defining these labels before the beginning of the studied code and upon its completion, you can calculate the difference, i.e. to obtain the actual time that was spent on code execution.

Functions microtime() and time()

In this example, the loop contains a different number of iterations: 567 or 56789. In the first case the cycle is faster in the second - ten times slower.

Author's example is not a picture

The Function microtime() can be used without any parameters, then the result will be a character string of two numbers separated by a space. The first number is the number of microseconds that the second number is the number of seconds that have elapsed since the date recognized as the beginning of the era of "UNIX".


How to get out of

How to get out of "Skype" on the "Android" and not only

How to get out of "Skype" "Android"? This question bothers many users. The thing is that the messenger is not so difficult. But there are features that are only for mobile versions. To log out of Skype in this case more difficult than it seems. But i...

Kingo ROOT: how to use the program to gain administrative rights on Android

Kingo ROOT: how to use the program to gain administrative rights on Android

The Gadgets on the platform Android regained the lion's share of the market. Developers are continually perfecting the OS, trying to fit the needs of the users, but from year to year admit palpable mistake: forbid the owner to "stuffing" of his gadge...

How to get from Stormwind to Tanaris: practical tips

How to get from Stormwind to Tanaris: practical tips

World of Warcraft is an iconic MMORPG, uniting millions of players around the world. There are many locations and puzzles, secret trails and larger, but rather dangerous paths. Sooner or later, every player chose the side of the Alliance, we have to ...

script sample

If the function microtime(true) is called with the parameter and its value is true, the result will be a number as a sum of seconds and microseconds. Using a function without parameters is equivalent to calling: microtime(false).

The time() Function works with microseconds, for example cycle on a smaller number of iterations gives a time of zero execution.

The Practical value of execution time

PHP is a fast, modern and functionally sophisticated language. In most cases the PHP script execution time even identify does not make sense. But the formation can be performed on the basis of data obtained from the database. In this case, apart from the delay information, can occur, and time for delivery of data to the accounting server load and other circumstances.

Advanced Internet programming often forced to reckon with the requirements of distributed data processing, need of data collection from various resources on the Network online. In these and similar cases, assessment of execution time of the script plays a strategic role and may have considerable practical value.

In particular, the development of a search engine may want to review systematically the range of a specific network resource on the subject executed on them changes over a period of time. But some resources can be:

  • Available;
  • Blocked;
  • To be on maintenance.

In these cases, the script will either crash or will be unreasonably long wait for the necessary events.

Setting a precise time for the execution of the script, for example, 10 sec., 1 min. or 5 min., you can provide your own resource strict observance of the rules for the processing of all the remote resources necessary to solve their problems.

Time and place of execution of the script

PHP is a server-side language, but it is not in all cases means the PHP script execution time is determined solely by the speed of the server. Only a limited number of tasks require server-side processing. Accessing a database or resource in the Network from a script is beyond the competence of the servers and additional time will be spent waiting for the establishment of the desired connections and obtaining the necessary data.

run php script

Run a PHP script can be done via AJAX technology, that is, after the click of the visitor on the page element. It is common practice, when the page is not updated as a whole, but only a single element. As a rule, such a decision may be due to the sample of the desired data. Any delay in the execution here is critical for the visitor. If the time exceeds his expectations, he'll just go on a fast and comfortable share.

The Developer can estimate how long it takes the required process, and if the PHP script execution time will start to go beyond acceptable limits, it can send to the visitor instead of an answer adequate to the message. This significantly increases the quality of the resource and is a good solution.

Article in other languages:













Alin Trodden - author of the article, editor
"Hi, I'm Alin Trodden. I write texts, read books, and look for impressions. And I'm not bad at telling you about it. I am always happy to participate in interesting projects."

Comments (0)

This article has no comment, be the first!

Add comment

Related News

Custom windows. How to create a LAN connection

Custom windows. How to create a LAN connection

With the development of network systems and technologies, the opportunity to combine a group of distributed computers in a network and call it the common working name. For example, workgroup. Such a network can be called local.Why...

Windows 8: remove the password when you log in to your account

Windows 8: remove the password when you log in to your account

If you are the only “user” of the computer on which moreover does not contain any important information, it is likely that you will want to get rid of the regular password when you log in to your account.of Course, whe...

How to make clip: review of programs and recommendations

How to make clip: review of programs and recommendations

How are the clips? How hard it is – to create a themed video in which are combined different types of files? Actually the answers are fairly simple, and every PC user will be able to create this little masterpiece. Videos. T...

Anyone can figure out how to take screenshots on a laptop

Anyone can figure out how to take screenshots on a laptop

the Laptop is a great modern solution for "advanced" people, that is why it is popular. Interesting things happen on the screens of users who wish to copy fragments of their work with computer equipment and keep for future referen...

BlueScreen (error): how to fix?

BlueScreen (error): how to fix?

“Blue screen of death”, or as it is called specialists BSOD – a protective reaction of the computer, suspending the system work before a potential failure of or damage. In certain situations BlueScreen (error) ap...

The strategy about the middle Ages: what is the cost to play

The strategy about the middle Ages: what is the cost to play

the development of the gaming industry is always impressive. Medicine, education, technology - none of that rushed forward as fast as entertainment. This applies not only to gambling, live quests, and more, but to computer develop...