文字

EventHttpConnection::setCloseCallback

(PECL event >= 1.8.0)

EventHttpConnection::setCloseCallbackSet callback for connection close

说明

public void EventHttpConnection::setCloseCallback ( callable $callback [, mixed $data ] )

Sets callback for connection close.

参数

callback

Callback which is called when connection is closed. Should match the following prototype:

void callback ([ EventHttpConnection $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
EventHttpRequest::getConnection()
$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();

?>
上一篇: 下一篇: