Asf_Application::setTimeoutHandler

(Asf >= 2.2.4)

PHP脚本执行时间耗时预警


Description

public bool Asf_Application::setTimeoutHandler(callable $timeout_handler)

Parameters

timeout_handler

callable

Return Values

设置成功返回 true, 否则会有异常信息提示

Examples

Example #1

<?php
function myTimeoutHandler($errno, $errstr)
{
    var_dump($errno, $errstr);
/*
    int(976)
    string(44) "/index/redis executing too slow 0.208992 sec"
*/
}

$handle = new Asf\Application($configs);
$handle->setTimeoutHandler('myTimeoutHandler');
$handle->run();

Example #2

<?php
class Debug
{
    public static function myTimeoutHandler($errno, $errstr)
    {
    }
}

$handle = new Asf\Application($configs);
$handle->setTimeoutHandler(array('Debug', 'myTimeoutHandler'));
$handle->run();

Example #3

<?php
class Debug
{
    public function myTimeoutHandler($errno, $errstr)
    {
    }
}

$handler = new Debug();

$handle = new Asf\Application($configs);
$handle->setTimeoutHandler(array($handler, 'myTimeoutHandler'));
$handle->run();

Example #4

<?php
class Bootstrap
{
    public function _initAlarm()
    {
        $app = Asf\Application::getInstance();
        $app->setTimeoutHandler(array($this, 'timeoutAlarm'));
    }

    public function timeoutAlarm($errno, $errstr)
    {
    }
}

$handle = new Asf\Application($configs);
$handle->bootstrap()->run();