rick645 Posted June 28 Share Posted June 28 (edited) https://www.php.net/manual/it/function.register-tick-function.php Specifically https://www.php.net/manual/it/control-structures.declare.php#control-structures.declare.ticks Quote A tick is an event that occurs for every N low-level tickable statements executed by the parser within the declare block. The value for N is specified using ticks=N within the declare block's directive section. Honestly, it's not very clear. Can someone explain it better? Edited June 28 by rick645 Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/ Share on other sites More sharing options...
requinix Posted June 28 Share Posted June 28 A tick happens every time the engine does something at a fairly granular level. Like executes a statement, but even lower-level than that. The easiest way to understand it is going to be to play with code: set up a ticket handler every 1/2/3/whatever ticks, have it output something, and then write a bunch of code to execute and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/#findComment-1655549 Share on other sites More sharing options...
rick645 Posted June 30 Author Share Posted June 30 (edited) On 6/28/2025 at 11:20 AM, requinix said: A tick happens every time the engine does something at a fairly granular level. Granular level? Quote Like executes a statement, but even lower-level than that. ???? I don't understand ???? Quote The easiest way to understand it is going to be to play with code: set up a ticket handler every 1/2/3/whatever ticks, have it output something, and then write a bunch of code to execute and see what happens. $ tree ├── tick1.php ├── tick2.php └── tick3.php $ cat tick1.php <?php declare(ticks=1); function my_tick_function() { debug_print_backtrace(); } register_tick_function('my_tick_function'); $ cat tick2.php <?php declare(ticks=2); function my_tick_function() { debug_print_backtrace(); } register_tick_function('my_tick_function'); $ cat tick3.php <?php declare(ticks=3); function my_tick_function() { debug_print_backtrace(); } register_tick_function('my_tick_function'); $ php tick1.php #0 /tmp/tmp.MLb8GRwmkU/tick1.php(5): my_tick_function() $ php tick2.php #0 /tmp/tmp.MLb8GRwmkU/tick2.php(5): my_tick_function() $ php tick3.php $ Why the php tick3.php command does not produce output? Edited June 30 by rick645 Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/#findComment-1655579 Share on other sites More sharing options...
Solution requinix Posted June 30 Solution Share Posted June 30 2 hours ago, rick645 said: Granular level? Yes, granular, as in "highly detailed; having many small and distinct parts". 2 hours ago, rick645 said: Why the php tick3.php command does not produce output? Because you missed the part in my reply where I said "write a bunch of code". You wrote a very small amount and you're not going to see how ticks work unless you write a lot more. Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/#findComment-1655580 Share on other sites More sharing options...
rick645 Posted June 30 Author Share Posted June 30 $ cat tick3.php <?php declare(ticks=3); function my_tick_function() { debug_print_backtrace(); } register_tick_function('my_tick_function'); abs(1); // added abs(1); // added abs(1); // added $ php tick3.php #0 /tmp/tmp.MLb8GRwmkU/tick3.php(6): my_tick_function() #0 /tmp/tmp.MLb8GRwmkU/tick3.php(8): my_tick_function() OK, thanks Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/#findComment-1655586 Share on other sites More sharing options...
requinix Posted July 1 Share Posted July 1 Sigh. I mean, if you're able to understand ticks from that then congratulations? Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/#findComment-1655609 Share on other sites More sharing options...
rick645 Posted July 3 Author Share Posted July 3 Il 01/07/2025 alle 07:44, requinix ha detto: Sigh. I mean, if you're able to understand ticks from that then congratulations? ???? Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/#findComment-1655729 Share on other sites More sharing options...
gizmola Posted July 3 Share Posted July 3 One thing that might be helpful is to use the declare to wrap the block of code you want to have evaluated for statement processing. $count = 0; function statements() { global $count; $count++; echo "Statement Count: $count\n"; } register_tick_function('statements'); declare(ticks=5) { for ($x = 0; $x < 10; $x++) { echo "\$x = $x \n"; } } And you get: $x = 0 $x = 1 $x = 2 $x = 3 $x = 4 Statement Count: 1 $x = 5 $x = 6 $x = 7 $x = 8 $x = 9 Statement Count: 2 1 Quote Link to comment https://forums.phpfreaks.com/topic/329083-register_tick_function-and-declareticks/#findComment-1655738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.