Runtime maksimum yürütme süresini tespit

3 Cevap php

PHP bu hata ile ilgili bir çok soru gördüm. Ancak zaman sınırı ayarlamak için çözüm verilen her yerde.

But what I want to do is, to detect the error and if it occurs then switch to another course of action. I mean, if my requests exceed my maximum time set, then it should not give an error message and stop but continue executing some other block of codes. How may I achieve that?

=======

Ben sadece bu kod yardımcı olabilir, bir site buldum?

<?php

//open error reporting, the error message is required in this script
error_reporting(1);

//for testing, set maximum execution to 1 second
set_time_limit(1);

//turn on output buffering and set callback function
ob_start('callback');

//------------------------------------------------------------------------------

//main program(dead loop)
while (true);

//script completed(impossible)
echo 'Completed!';

//------------------------------------------------------------------------------

/**
 * output callback, execute when end of the request
 *
 * @param string $buffer
 * @return string
 */
function callback($buffer) {
    if (false !== (stripos($buffer,'<b>Fatal error</b>'))) {
        if (false !== (stripos($buffer,'Maximum execution'))) {
            $buffer = 'ycTIN.com , Server Busy';
        } else {
            $buffer = 'ycTIN.com , Server Internal Error';
        }
    }
    return $buffer;
}
?>

3 Cevap

Daha sonra hiçbir şekilde sanırım. Ben sadece zaman sınırı sonsuz ayarlanır. Bu yolu bazen bitmeli .. :)

Lütfen maksimum yürütme süresini aşan php ölümcül bir hata neden olur çünkü yapılamaz

Eğer maksimum yürütme zamanı daha küçük değerine ayarlarsanız pcntl_alarm yardımcı olabilir.