开发者

set_time_limit callback?

Is it possible to set a "callback function" that do something instead of returning an开发者_运维百科 error whe the time limit is reached?


You could remove the time limit (set_time_limit(0)), and then keep track of the time the PHP script started executing and make a comparison with the current time.

<?php

$startTime = microtime();

// Whatever you need to do...

// Place this where it needs to be in the context of your application.
if (microtime() - $startTime > 15000) { 
    // Time's up!
}


I don't think so...that kind of defeats the point of the function to begin with... I think if you wanna do something like that, set it to 0 (no time limit) and keep track of the time a different way and do something after X time.


As others have said no. If your script is timing out because of external factors (like it doesn't come back from a single function call), then your only remedy may be to use pcntl_alarm and pcntl_signal. Allthough I'm not sure these can be used in sapi's other then CLI.


You can Try this one : http://www.php.net/register_shutdown_function

function shutdown()
{
    // This is our shutdown function, in 
    // here we can do any last operations
    // before the script is complete.

    echo 'Script executed with success', PHP_EOL;
}

register_shutdown_function('shutdown');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜