Laravel 5.3:是什么导致了 'maximum execution time of 30 seconds exceeded'

Laravel 5.3: What is causing 'maximum execution time of 30 seconds exceeded'

问题

我正在使用 Laravel 5.3 使用控制器代码中的函数将一个巨大的(大约 >1 million rows>25 columns)制表符分隔文件导入 mysql 数据库(我正在限制从这里发布所有代码)。处理文件时遇到以下错误:

FatalErrorException in Connection.php line 720:

Maximum execution time of 30 seconds exceeded

请注意,应用程序在失败前为不同的实例导入了不同数量的行。

问题

我知道我们可以使用以下任一方法解决此问题:

  1. 更改 php.ini 建议
  2. 按照建议在 public/index 开头添加 ini_set('max_execution_time', 300); here

这背后可能有多种原因,我更想 想知道它的确切位置 运行 过时 Laravel 没有提供比上述更多的细节。如果有人可以提供调试方法,我将不胜感激。有帮助的事情:

环境

不是特定的操作运行超时了。它是...一切,从开始到结束。

max_execution_time integer

This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30.

http://php.net/manual/en/info.configuration.php#ini.max-execution-time

这里的想法是,对于网络服务,一般来说,从请求到响应只有一定的时间是合理的。显然,如果需要 30 秒("reasonableness" 的任意数字)到 return 对 Web 浏览器或 API 的响应,则可能没有按预期工作。大量占用服务器资源的请求会导致服务器对任何后续请求无响应,从而导致整个站点瘫痪。

max_execution_time 参数是一种保护性控制,用于在脚本(例如)陷入无限循环或以其他方式运行不合理的时间量时减轻站点的降级。脚本执行终止,释放正在消耗的资源,通常以非生产方式。

Is the time aggregate of all requests by a method?

这是脚本中所有内容的总运行时间 -- 不是一个特定的操作。

Does memory overload cause this?

通常不会,除非当系统内存受限并使用交换文件时,因为交换抖动会消耗大量时间。

Will it help by chunking the data and handling it through multiple request?

在这种情况下,是的,使用较小的批处理可能有意义,这(一般来说)应该会减少运行时间。一切都是权衡,因为就每单位工作的处理时间而言,更大的批次可能更有效,也可能不更有效,这是特定于工作负载的,很少是线性的。