PHP max_execution_time如何工作? [英] How does PHP max_execution_time work?

查看:78
本文介绍了PHP max_execution_time如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对php.ini中设置的最大执行时间毫无疑问.

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

假设max_execution_time为3分钟,请考虑以下情况:

Assuming max_execution_time is 3 minutes, consider the following cases:

  1. 我有一个过程将在2分钟内结束.

  1. I have a process which will end in 2 minutes.

但是它处于循环状态,应该可以工作5次.这样就变成了10分钟.

But it's in a loop and it should work 5 times. So it become 10 minutes.

脚本是否可以正常运行而不会显示超时错误?为什么?

Will the script run properly without showing error for timeout? Why?

PHP函数仅打印数据,仅需2分钟.

PHP function just prints the data and it will take only 2 minutes.

但是查询执行需要5分钟.

But the query execution is taking 5 minutes.

脚本将正确运行吗?为什么?

Will the script run without error? Why?

我的单个php进程本身需要5分钟.

My single php process itself take 5 minutes.

但是我是从命令行调用脚本的.

But am calling the script from command line.

它将正常工作吗?为什么?

Will it work properly? Why?

允许的内存与执行时间有何关系?

How are memory allowed and execution time related?

如果脚本的执行时间非常长

If execution time for a script is very high

但是它返回少量数据

会影响内存吗?为什么?

Will it affect memory or not? Why?

我想了解内部正在发生的事情,这就是为什么要问这些问题. 我不想只是增加时间限制和内存限制.

I want to learn what is happening internally, that is why am asking these. I don't want to just increase time limit and memory limit.

推荐答案

max_execution_time上的规则相对简单.

  • 解释文件时,执行时间开始计时.准备请求,准备上传的文件,Web服务器执行其工作等所需的时间不计入执行时间.

  • 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.

执行时间是脚本运行的总时间,包括数据库查询,无论它是否循环运行.因此,在第一种和第二种情况下,脚本将以超时错误终止,因为这是max_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.

使用exec()进行的外部系统调用,除了Windows以外,不计入执行时间. ()这意味着您可以运行一个外部程序来花费的时间长于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.

从命令行调用时,max_execution_time默认为0. ()因此,在第三种情况下,您的脚本应运行没有错误.

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.

这篇关于PHP max_execution_time如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆