If you include a file in PHP within a loop will it access the file every time it runs in the loop?

前端 未结 3 1210
暖寄归人
暖寄归人 2020-12-21 13:34

If you have this

for($i = 0; $i < 10; $i++) include(\'whatever.php\');

Will it pull the file ten actual times, or will it only access th

3条回答
  •  误落风尘
    2020-12-21 13:58

    Simple enough to check - put a sleep() in there, have the file do some output, and during one of the sleep periods, modify the file to change its output.

    whatever.php:

    then during one of the sleeps, change it to "version 2.0" using another shell. If the output doesn't change, then PHP has loaded the file ONCE and cached it - you'll still get 10 copies of the file's output/effects, but you'll know that PHP didn't hit the disk 10 times.

提交回复
热议问题