©
このドキュメントでは、 php中国語ネットマニュアル リリース
(PECL event >= 1.8.0)
EventHttpConnection::setCloseCallback — Set callback for connection close
$callback
[, mixed $data
] )Sets callback for connection close.
callback
Callback which is called when connection is closed. Should match the following prototype:
$conn
= NULL
[, mixed $arg
= NULL
]] )没有返回值。
Example #1 EventHttpConnection::setCloseCallback() example
<?php
function _close_callback ( $conn )
{
echo __FUNCTION__ , PHP_EOL ;
}
function _http_default ( $req , $dummy )
{
$conn = $req -> getConnection ();
$conn -> setCloseCallback ( '_close_callback' , NULL );
$bev = $req -> getBufferEvent ();
$bev -> enable ( Event :: READ );
// We have to free it explicitly. See
$bev->free(); // we have to free it explicitly
$req->addHeader(
'Content-Type',
'multipart/x-mixed-replace;boundary=boundarydonotcross',
EventHttpRequest::OUTPUT_HEADER
);
$buf = new EventBuffer();
$buf->add('<html>');
$req->sendReply(200, "OK");
$req->sendReplyChunk($buf);
}
$port = 4242;
if ($argc > 1) {
$port = (int) $argv[1];
}
if ($port <= 0 || $port > 65535) {
exit("Invalid port");
}
$base = new EventBase();
$http = new EventHttp($base);
$http->setDefaultCallback("_http_default", NULL);
$http->bind("0.0.0.0", $port);
$base->loop();
?>