PHP 脚本第一行超过最大执行时间

PHP maximum execution time exceeded on first line of script

我在 PHP 自己的错误日志中遇到间歇性错误,如下所示:

09-Mar-2015 09:18:12 Europe/Dublin] PHP Fatal error: Maximum execution time of 120 seconds exceeded in C:\inetpub\site\www\index.php on line 27

该应用程序在 CakePHP 上运行,因此 index.php 只是 Cake 的普通请求处理程序。对应用程序的每个请求都通过此文件。

该站点在 Windows/IIS 中的 PHP 5.4 上运行。 IIS 自己的此特定请求日志显示这是一个 POST 请求。

这是index.php。第 27 行是注释之后的第一行实际代码,因此可以安全地假设它是 PHP 尝试根据请求执行的第一行。

<?php
/**
 * Requests collector.
 *
 *  This file collects requests if:
 *  - no mod_rewrite is available or .htaccess files are not supported
 *  - requires App.baseUrl to be uncommented in app/Config/core.php
 *  - app/webroot is not set as a document root.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 *  Get Cake's root directory
 */
define('APP_DIR', 'app');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);

/**
 * This only needs to be changed if the "cake" directory is located
 * outside of the distributed structure.
 * Full path to the directory containing "cake". Do not add trailing directory separator
 */
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
}

require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';

这里有两个问题。

首先,到底是什么导致了这个问题?一些我没有想到的 IIS 或 PHP 设置?我无法在开发中重现它。

其次,遇到此错误的用户只会得到白屏死机,因为 CakePHP 框架尚未启动并注册关闭函数或错误处理程序。任何关于我如何至少用一个优雅的 "Something went wrong, please try again" 来处理这个问题的临时想法都是有用的。您不能在 index.php 中使用 register_shutdown_function(),因为它会覆盖 CakePHP 的错误处理程序。

问题原来是 max_input_time 设置的值太低了。只有连接速度慢且上传大文件的用户才会遇到此问题。我在 php.ini 中增加了 max_input_time,问题消失了。