Php 检查上传是否花费太多时间,以防通知用户?
当用户以慢速Internet连接上传大量文件时,我会尝试检测PHP脚本执行超时:我应该只警告用户超时 我在我的Php 检查上传是否花费太多时间,以防通知用户?,php,file-upload,upload,timeout,Php,File Upload,Upload,Timeout,当用户以慢速Internet连接上传大量文件时,我会尝试检测PHP脚本执行超时:我应该只警告用户超时 我在我的upload.php和on_shutdown()中使用了,我创建了一个$timeout标志,用于complete.php检测超时 问题是结果完全错误:我有一个超时致命错误(没问题),一个require致命错误(在函数require($require),就好像$require是空的)和complete.php没有显示 太糟糕了,我不知道我错在哪里。这是(短版本)upload.php脚本:
upload.php
和on_shutdown()
中使用了,我创建了一个$timeout
标志,用于complete.php
检测超时
问题是结果完全错误:我有一个超时致命错误(没问题),一个require致命错误(在函数require($require)
,就好像$require
是空的)和complete.php
没有显示
太糟糕了,我不知道我错在哪里。这是(短版本)upload.php
脚本:
<?php
register_shutdown_function('on_shutdown');
$require = 'complete.php'; // Complete page
sleep(50); // fake timeout for testing
// Do stuff, save files, insert into database...
// This always invoked
function on_shutdown()
{
global $require;
$timeout = connection_status() == 2;
require($require);
}
?>
寄存器_shutdown_函数(“on_shutdown”);
将仅在执行脚本后运行
“在脚本执行完成或调用exit()后注册要执行的回调。”-php.net
您可以检查最大执行时间的值并将其分配给0以进行长时间执行,而不是尝试超时,但不建议使用安全性方面的0
$maxExeTime = ini_get('max_execution_time'); //this will get maxumum excetion time for PHP script in seconds
echo $maxExeTime;
你们也可以检查下面的全局变量
$postMs = ini_get('post_max_size'); //this will get maxumum size of data to be accepted in $_POST
$upMaxFiles = ini_get('upload_max_filesize'); //this will get maxumum allowed file size for file upload
$noFilesUp = ini_get('max_file_uploads'); //this will get number of files to be load on single request
为什么不在上传页面上使用
设置时间限制(0)
,让他们上传文件?我只是问…顺便说一句,当您第一次声明$require
时,您应该使用global$require='complete.php'除非我弄错了。
$postMs = ini_get('post_max_size'); //this will get maxumum size of data to be accepted in $_POST
$upMaxFiles = ini_get('upload_max_filesize'); //this will get maxumum allowed file size for file upload
$noFilesUp = ini_get('max_file_uploads'); //this will get number of files to be load on single request