PHP Classes

File: example/Example/withoutReachingLimit.php

Recommend this page to a friend!
  Classes of nvb   PHP Time Limit Manager   example/Example/withoutReachingLimit.php   Download  
File: example/Example/withoutReachingLimit.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Time Limit Manager
Check if the PHP execution time limit was reached
Author: By
Last change:
Date: 4 years ago
Size: 891 bytes
 

Contents

Class file image Download
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2014-07-26
 */

require_once __DIR__ . '/../../vendor/autoload.php';

echo
'starting example' . PHP_EOL;

$startTime = time();

$manager = new Net\Bazzline\Component\TimeLimitManager\TimeLimitManager();
$manager->setBufferInSeconds(0);
$manager->setLimitInSeconds(9);

$scriptRunTimeInSeconds = 9;

for (
$iterator = 0; $iterator < $scriptRunTimeInSeconds; ++$iterator) {
    if (
$manager->isLimitReached()) {
        echo
'runtime of ' . $manager->getLimitInSeconds() . ' seconds limit reached' . PHP_EOL;
        exit(
1);
    }

   
$iteratorIsEven = (($iterator % 2) === 0);

    if (
$iteratorIsEven) {
        echo
'Tick ' . PHP_EOL;
    } else {
        echo
'Tack ' . PHP_EOL;
    }

   
sleep(1);
}

$runTimeInSeconds = (time() - $startTime);

echo
'finished example in ' . $runTimeInSeconds . ' seconds' . PHP_EOL;