Phalcon Micro Application(facing prob with finish middleware event)

I'm facing a problem while implementing micro application in which I want a middle ware that is executed after response is send to browser. As mentioned in documentation of Phalcon *finish middle ware * suppose to that work but its not working, browser still waiting to complete whole process then it return response.

my code is like:

$app->before(function() use ($app, $di) {
        $di->get('log')->log("This is a message before");
        $di->get('log')->close();
    });

    $testCtrl = new testCtrl();
    $app->get('/ctrltest', array($testCtrl, "indexAction"));

    $app->after(function() use ($app, $di) {
         echo "after";
        $di->get('log')->log("This is a message after");
        $di->get('log')->close();
    });

    $app->finish(function() use ($app, $di) {
            $count = 100000;
            while ($count) {
                $di->get('log')->log("count " . $count);
                $count--;
            }
    });

Response are coming after whole loop is executed. Any sample code or some suggestion will be helpful

You are looking for fastcgi_finish_request

http://php.net/manual/en/function.fastcgi-finish-request.php

$app->after(function() use ($app, $di) {
    fastcgi_finish_request();
    $di->get('log')->log("This is a message after");
    $di->get('log')->close();
});


488

Thanks david, But this function fastcgifinishrequest(); thowing a error Call to undefined function fastcgifinishrequest()

edited Nov '15

You need to use FPM as SAPI in order to use php fastcgi_finish_request();

http://php.net/manual/en/ref.fpm.php