简体   繁体   中英

php script taking longer than max_execution_time

i am trying to limit the maximum time of php script. in php.ini i have 30seconds.

in a script i wrote:

<?php
echo ini_get('max_execution_time');
ini_set('max_execution_time', 3);
echo ini_get('max_execution_time');

$cp=1;
while (1 == 1) {
  $cp++;
  $date = @date("Y-m-d H:i:s");
  echo "<li>$cp $date";
} 
?>

But when on the browser i get the first line:

2019-02-19 19:43:38 and on the last: 302688 2019-02-19 19:44:15

I dont understand, it should stop after 3 seconds: so at 19:43:41

Thanks all, good evening

You might want to calculate the microtime running a script. Something like:

<?php
$start_time = microtime(true);

while (microtime(true)-$start_time<3)
{
  $date=@date("Y-m-d H:i:s");
  echo "<LI>$cp $date";
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM