declare does also support an alternative syntax (see control-structures.alternative-syntax):
<?php
declare (ticks=1):
// Funky shizzle
enddeclare;
?>
As you can see, enddeclare is (highlighted as) a keyword.
![]() |
|
||||||||||
|
declareThe declare construct is used to set execution directives for a block of code. The syntax of declare is similar to the syntax of other flow control constructs: The directive section allows the behavior of the declare block to be set. Currently only one directive is recognized: the ticks directive. (See below for more information on the ticks directive) The statement part of the declare block will be executed -- how it is executed and what side effects occur during execution may depend on the directive set in the directive block. The declare construct can also be used in the global scope, affecting all code following it.
TicksA tick is an event that occurs for every
The event(s) that occur on each tick are specified using the register_tick_function(). See the example below for more details. Note that more than one event can occur for each tick.
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(). declare
zsh
04-Oct-2007 04:13
declare does also support an alternative syntax (see control-structures.alternative-syntax):
rosen_ivanov at abv dot bg
28-Aug-2006 06:06
As Chris already noted, ticks doesn't make your script multi-threaded, but they are still great. I use them mainly for profiling - for example, placing the following at the very beginning of the script allows you to monitor its memory usage:
aeolianmeson at NOSPAM dot blitzeclipse dot com
30-May-2006 12:06
The scope of the declare() call if used without a block is a little unpredictable, in my experience. It appears that if placed in a method or function, it may not apply to the calls that ensue, like the following:
warhog at warhog dot net
18-Dec-2005 12:39
as i read about ticks the first time i thought "wtf, useless crap" - but then i discovered some usefull application...
chris-at-free-source.com
28-Feb-2005 12:16
Also note that PHP is run in a single thread and so everything it does will be one line of code at a time. I'm not aware of any true threading support in PHP, the closest you can get is to fork.
fok at nho dot com dot br
07-Jul-2003 06:45
This is a very simple example using ticks to execute a external script to show rx/tx data from the server
daniel@swn
01-Feb-2003 11:56
<?php
xxoes
08-Jan-2003 02:23
If i use ticks i must declare all functions before i call the function.
rob_spamsux at rauchmedien dot ihatespam dot com
19-Mar-2002 02:45
Correction to above note:
rob_spamsux at rauchmedien dot ihatespam dot com
19-Mar-2002 01:58
Here is an example of multi-tasking / multi-threading: |