Re: _sleep(),__wakeup(), phpticks

From: Date: Mon, 11 Dec 2000 19:57:09 +0000
Subject: Re: _sleep(),__wakeup(), phpticks
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-40894@lists.php.net to get a copy of this message
On Mon, 11 Dec 2000, André Langhorst wrote: > Do we have no information about __sleep()/__wakeup() and the way how php > ticks work? I just realized that there is no information about them in > the documentation deleting some old mails... Someone was going to write docs about ticks, let me check. Ok, Daniel Beckham contacted me and I sent him some docs on what they are about, but apparently, no docs materialized out of that? Well, anyway, here's an accumulation of several messages. ---------------------- I've just added support for userland PHP tick callback functions. This can be used to simulate background processing. Usage example: <? function foo($a) { print "$a\n"; } function zoo() { static $i = 0; print "I am: $i\n"; $i++; } register_tick_function("foo", "I'm here!"); register_tick_function("zoo"); declare (ticks = 3) { 1;1; 1;1; 1;1; } ?> This would output: I'm here! I am: 0 I'm here! I am: 1 It's also possible to use array($obj, 'method') syntax for callbacks, and there is unregister_tick_function() as well. ---------------------- Ok, basically, Zend engine has a feature where after execution of a certain number of statements (ticks) it can call another function. This ia all C API for now. What I've done is made that C function go through a list of PHP registered functions and call them one-by-one after the specified number of 'ticks' has been executed. So, in a nutshell, you register a callback function that gets called after N statements have been executed. N is controlled by 'declare' directive, e.g.: declare (ticks=4) { .. } Anything inside the directive block will enable ticks functionality and will call the registered functions every 4 statements. It's possible to register the same function more than once. The functions are executed in the order they were registered, not simultaneously. It's possible to register array($obj, 'method') as a callback as well. ---------------------- On Wed, 06 Sep 2000, Daniel Beckham wrote: > Ok, I believe I get the gist of what it is supposed to do. How is the > number of ticks determined? I'm afraid that I've never used declare() in my > PHP code before and I don't see it mentioned in the docs anywhere, although > I see it in "Zend/zend-scanner.l". Or was that to illustrate a point? =) It's a new construct. It's only used for ticks for now, but may be used for something else in the future. declare(keyword = arg) { .. } Basically used to apply some options to the enclosed code. For ticks it would be: declare (ticks = N) { .. } Where N is the number of ticks after which the functions will be called. > Also, let me make sure I'm clear on a few things: > > The statements (ticks) are referring to C statements in Zend, or user > written PHP statements? I'm assuming that it's C statements in Zend, but I > want to be absolutely clear. No, it's user written PHP statements. > It looks like the tick function you register won't necessarily be executed > in a consistent manner, or only however long it takes to execute a certain > number of tick statements? Yes, if you have enclosed 3 statements that are in the for loop that is repeated 10 times then you have 30 statements total I believe (unless Zend splits them up a little differently). Anyway, it's not meant as a precise tool, more like "do this every once in a while". > And lastly, the arguments [, mixed arg [, ... ]] for > register_tick_function() are arguments for the function name supplied? Yes, exactly. ---------------------- -Andrei "I think it would be a good idea." -- Mahatma Gandhi, when asked what he thought of Western civilization...

« previous php.dev (#40894) next »