event_buffer_timeout_set
(PECL libevent >= 0.0.1)
event_buffer_timeout_set — Set read and write timeouts for a buffered event
Description
void event_buffer_timeout_set
( resource
$bevent
, int $read_timeout
, int $write_timeout
)Sets the read and write timeouts for the specified buffered event.
Parameters
-
bevent
-
Valid buffered event resource.
-
read_timeout
-
Read timeout (in seconds).
-
write_timeout
-
Write timeout (in seconds).
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для управления процессами программ
- Libevent
- event_add
- event_base_free
- event_base_loop
- event_base_loopbreak
- event_base_loopexit
- event_base_new
- event_base_priority_init
- event_base_reinit
- event_base_set
- event_buffer_base_set
- event_buffer_disable
- event_buffer_enable
- event_buffer_fd_set
- event_buffer_free
- event_buffer_new
- event_buffer_priority_set
- event_buffer_read
- event_buffer_set_callback
- event_buffer_timeout_set
- event_buffer_watermark_set
- event_buffer_write
- event_del
- event_free
- event_new
- event_priority_set
- event_set
- event_timer_add
- event_timer_del
- event_timer_new
- event_timer_set
Коментарии
On timeout the error callback is executed. This can be very valuable if you wanted to monitor inactivity on a socket.
You also need to use event_buffer_enable if you wanted to re-use the event listener.
Example:
<?php
function print_line($buf, $arg)
{
static $max_requests;
$max_requests++;
if ($max_requests == 10) {
event_base_loopexit($arg);
}
// print the line
echo event_buffer_read($buf, 4096);
}
function error_func($buf, $what, $arg)
{
// If this was a read timeout
if ($what == (EVBUFFER_READ | EVBUFFER_TIMEOUT)) {
echo '5 seconds of inactivity'."\n";
// Control timeout features
// Could ping the client, or even disconnect the client if you really wanted to.
// --- ETC
// Restart our event loop on this buffer
event_buffer_enable($buf, EV_READ);
}
}
$base = event_base_new();
$eb = event_buffer_new(STDIN, "print_line", NULL, "error_func", $base);
// Timeout after 5 seconds of inactivity
event_buffer_timeout_set($eb, 5, NULL);
event_buffer_base_set($eb, $base);
event_buffer_enable($eb, EV_READ);
event_base_loop($base);
?>