Lecture
The declare declaration construct is used to set the execution directives for a block of code. The declare syntax is similar to the syntax of other PHP control constructs:
declare (директива)
инструкция;
The directive allows you to set the behavior of the declare block. Currently, only one directive is available in PHP - tick . The instruction is part of the declare block.
How the instruction (s) will be executed depends on the directive.
The declare construct can be used in a global scope, affecting all the code after it.
<?php
// Вы можете равнозначно использовать следующие методы
// Так:
declare(ticks=1) {
// Здесь полный сценарий
}
// Или так:
declare(ticks=1);
// Здесь полный сценарий
?>
Tick directive
tick is an event that occurs for every lower-level N-instructions executed by the parser within the declare block. Events occurring on each tick are determined by the register_tick_function () function.
The declare construct is used to set the execution directives for a block of code. The declare syntax is similar to the syntax of other flow control constructs:
declare (directive) statement |
The directive section allows you to set the declare block behavior. Currently only one directive is recognized: ticks . (See further about the ticks directive.)
The statement part of the declare block will be executed — how it is executed and which side effects occur during execution depends on the directive set in the directive block.
A tick / tick is an event that occurs for each lower-level operator N performed by the parser inside the declare block. The value of N is specified by ticks = N inside the directive section of the declare block.
The event (s) that occurs with each tick is specified by the register_tick_function () function. See details further in the example. Note that more than one event may occur for each tick.
Example 11-1. Profiling the PHP code section
|
This example profiles the PHP code inside the 'declare' block, recording the time when each second low-level statement of the executed block is executed. This information can then be used to search for slow sections of a specific code segment. This process can be performed using other methods: the use of ticks is more convenient and easier to implement.
Ticks are well suited for debugging, implementing simple multitasking, background I / O, and many other tasks.
See also register_tick_function () and unregister_tick_function () .
Comments
To leave a comment
Running server side scripts using PHP as an example (LAMP)
Terms: Running server side scripts using PHP as an example (LAMP)