libevent; example not working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I installed the libevent package, and as a test, tried [Example 
#1][http://us2.php.net/manual/en/libevent.examples.php] with a few 
modifications ( below; read from a file instead of stdin; write output to 
php log file ). I'm not seeing callback_func() being called, and I'm not 
seeing any errors, segfaults, etc ( I see my "ex1: started event loop" debug 
msg ).

I'm using PHP 5.1.6 on Red Hat 3.4.6-2, and re: installation, I followed 
steps 4-9, and believe everything is installed properly:

http://abhinavsingh.com/blog/2009/11/writing-a-custom-unix-style-tail-in-php-using-libevent-api-on-mac-os-x-10-5-x-and-other-platforms/

Any suggestions on how to go about getting this to work ? Thanks,



<?php

function callback_func($fd, $events, $arg) {

error_log( "callback_func(): here !" );

static $max_requests;

$max_requests++;

if ($max_requests == 10) { /* exit loop after 10 writes */

event_base_loopexit($arg[1]);

}

/* read while we can */

$data = fread($fd, 4096);

while (false !== $data) {

//echo $data;

error_log( "callback_func(): data = " . $data );

$data = fread($fd, 4096);

}

}

/* create base and event */

$base = event_base_new();

$event = event_new();

//$fd = STDIN;

$fd = fopen( "/dev/apache/logs/access_log", 'r' );

/* set event flags */

event_set($event, $fd, EV_READ | EV_PERSIST, "callback_func", array($event, 
$base));

/* set event base */

event_base_set($event, $base);

/* enable event */

event_add($event);

/* start event loop */

error_log( "ex1: starting event loop" );

event_base_loop($base);

error_log( "ex1: started event loop" );

while( 1 );

?>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux