Re: [PHP-PEAR] event-based oop design

[email protected] ((Stig Sæther Bakken)) 15 Mar 2001 02:26:01 +0100
Newsgroups php.pear
Message-ID <[email protected]>
Hi Jesus,

PHP has a feature called "ticks" that lets you do cooperative
multitasking in a PHP request.  A tick is a callback from Zend for
every N statements processed.  Example:

<?php

function tick($arg) {
    print "[tick, arg=$arg]\n";
}

register_tick_function("tick", 42);

// these statements are not "ticked":
1;1;1;1;

declare (ticks = 1) {
    // these statements are "ticked":
    1;1;1;1;
}

?>

You could use this to implement polling of an "event bus", but if you
implement that in PHP you'll come back as a toad in your next
life. ;-)

 - Stig

["Jesus M. Castagnetto" <[email protected]>]
> For event based classes to work, would'nt you need
> threads? In java, usually you have listener objects
> and any instance interested in a particular event
> registers with the listener (or a listeners' manager
> object), and then the listener informs the registered
> class when the event occurs, oftentimes this will
> spawn a new thread.
> 
> Can't see how this can be done in PHP w/o some
> contortions. Perhaps in an application server in which
> scripts live, like servlets in a servlet server.
> 
> As for error reporting, you can always define your own
> error handler(s) in PHP, it is not event based
> java-style, but it will work. Check out the example I
> wrote for the manual entry of set_error_handler().
> 
> Perhaps error handling can be implemented similarly to
> how destructors are implemented in PEAR.
> 
> --- Uioreanu Calin <[email protected]> wrote:
> > Hello,
> > 
> > Has anyone knowledge of an event based classes
> > structure?
> > Error reporting&about everything could gain
> > dimension.
> > 
> > Regards,
> > Calin
> > 
> > 
> > 
> > -- 
> > PHP Extension and Add-on Repository (PEAR) mailing
> > list.
> > Documentation can be found at
> > http://pear.php.net/doc/pear.html
> > To unsubscribe, e-mail:
> > [email protected] from the
> > mail address you subscribed with.
> > 
> 
> 
> =====
> --- Jesus M. Castagnetto ([email protected])
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - Buy the things you want at great prices.
> http://auctions.yahoo.com/
> 
> -- 
> PHP Extension and Add-on Repository (PEAR) mailing list.
> Documentation can be found at http://pear.php.net/doc/pear.html
> To unsubscribe, e-mail: [email protected] from the
> mail address you subscribed with.
> 

-- 
  Stig Sæther Bakken <[email protected]>
  Fast Search & Transfer ASA, Trondheim, Norway