How does PHP max_execution_time work?

后端 未结 1 757
时光取名叫无心
时光取名叫无心 2020-12-05 11:16

I have few doubts about maximum execution time set in php.ini.

Assuming max_execution_time is 3 minutes, consider the following cases:

  1. I have a proc

相关标签:
1条回答
  • 2020-12-05 11:55

    The rules on max_execution_time are relatively simple.

    • Execution time starts to count when the file is interpreted. Time needed before to prepare the request, prepare uploaded files, the web server doing its thing etc. does not count towards the execution time.

    • The execution time is the total time the script runs, including database queries, regardless whether it's running in loops or not. So in the first and second case, the script will terminate with a timeout error because that's the defined behaviour of max_execution_time.

    • External system calls using exec() and such do not count towards the execution time except on Windows. (Source) That means that you could run a external program that takes longer than max_execution_time.

    • When called from the command line, max_execution_time defaults to 0. (Source) So in the third case, your script should run without errors.

    • Execution time and memory usage have nothing to do with each other. A script can run for hours without reaching the memory limit. If it does, then often due to a loop where variables are not unset, and previously reserved memory not freed properly.

    0 讨论(0)
提交回复
热议问题