Example usage of the declare construct with the ticks directive

http://uk.php.net/manual/en/control-structures.declare.php

http://uk.php.net/manual/en/function.register-tick-function.php

WARNING: Crashes Apache in multi-threaded environment!

register_tick_function() should not be used with threaded web server modules with PHP 5.2 or lower.

Example#1

This crashes the server!


<?php
declare(ticks=1);

// A function called on each tick event
function tick_handler() {
    echo 
"tick_handler() called\n";
}

register_tick_function('tick_handler');

$a 1;

if (
$a 0) {
    
$a += 2;
    print(
$a);
}
?>

Example#2

tick_handler() called tick_handler() called 3tick_handler() called tick_handler() called

[Home]