downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Libevent Functions> <Predefined Constants
Last updated: Wed, 25 Nov 2009

view this page in

Examples

Example #1 polling STDIN using basic API

<?php

function callback_func($fd$events$arg)
{
    static 
$max_requests;

    
$max_requests++;

    if (
$max_requests == 10) { /* exit loop after 10 writes */
        
event_base_loopexit($arg[1]);
    }

    
/* read while we can */
    
while (false !=== ($data fread($fd4096))) {
        echo 
$data;
    }
}

/* create base and event */
$base event_base_new();
$event event_new();

$fd STDIN;

/* set event flags */
event_set($event$fdEV_READ EV_PERSIST"callback_func", array($event$base));
/* set event base */
event_base_set($event$base);

/* enable event */
event_add($event);
/* start event loop */
event_base_loop($base);

?>

Example #2 polling STDIN using buffered event API

<?php

function callback_func($buf$arg)
{
    static 
$max_requests;

    
$max_requests++;

    if (
$max_requests == 10) {
        
event_base_loopexit($arg);
    }

    
/* read while we can */
    
while (false !=== ($data event_buffer_read($buf10))) {
        echo 
$data;
    }
}

function 
error_func($buf$what$arg)
{
    
/* handle an error */
}

$base event_base_new();
$b event_buffer_new(STDIN"callback_func"NULL"error_func"$base);

event_buffer_base_set($b$base);
event_buffer_enable($bEV_READ);

event_base_loop($base);

?>



add a note add a note User Contributed Notes
Examples
There are no user contributed notes for this page.

Libevent Functions> <Predefined Constants
Last updated: Wed, 25 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites