note 108044 added to function.event-buffer-timeout-set
| From: | john at collabriasoftware dot com | Date: | Sat, 24 Mar 2012 02:38:55 +0000 |
| Subject: | note 108044 added to function.event-buffer-timeout-set | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186801@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 64.71.164.2
Probable Submitter: 24.92.26.122
----
Manual Page -- http://www.php.net/manual/en/function.event-buffer-timeout-set.php
Edit -- https://master.php.net/note/edit/108044
Del: integrated -- https://master.php.net/note/delete/108044/integrated
Del: useless -- https://master.php.net/note/delete/108044/useless
Del: bad code -- https://master.php.net/note/delete/108044/bad+code
Del: spam -- https://master.php.net/note/delete/108044/spam
Del: non-english -- https://master.php.net/note/delete/108044/non-english
Del: in docs -- https://master.php.net/note/delete/108044/in+docs
Del: other reasons-- https://master.php.net/note/delete/108044
Reject -- https://master.php.net/note/reject/108044
Search -- https://master.php.net/manage/user-notes.php