简体   繁体   English

函数超过了最大执行时间

[英]function exceeds maximum execution time

I have this function and most of the time when I run this function the following error occurs: 我具有此功能,并且在大多数情况下,运行此功能时会发生以下错误:

Fatal error: Maximum execution time of 30 seconds exceeded 致命错误:超过30秒的最大执行时间

The location (line) of the error is always different. 错误的位置(线)总是不同的。

And this is the function: 这是函数:

            function selectAdsY(){
                //Put all the ads in the arrays.    

                global $ads;
                global $adsX;
                global $adsY;
                global $Min;
                global $ImpIfriends;
                global $ImpLivejasmin;
                global $ImpExo;
                global $ImpND;
                global $ImpAmazon;

                // Change these 
                $ImpIfriends = 20;
                $ImpLivejasmin = 10;
                $ImpExo = 0;
                $ImpND = 20;
                $ImpAmazon = 20;

                $i = 0;
                //ifriends
                    global $ifriends;
                    global $ifriendsX;
                    global $ifriendsY;
                    $iframeCountFriends = count($ifriends) - 1;
                    $a = rand(0, $iframeCountFriends);

                $ads[$i] = $ifriends[$a];
                    $adsX[$i] = $ifriendsX[$a];
                    $adsY[$i] = $ifriendsY[$a];
                if($ImpIfriends != 0){
                    $Min[$i] = min($ifriendsY);
                }

                //livejasmin
                    global $livejasmin;
                    global $livejasminX;
                    global $livejasminY;
                    $iframeCountLivejasmin = count($livejasmin) - 1;
                    $a = rand(0, $iframeCountLivejasmin);
                $i++;
                $ads[$i] = $livejasmin[$a];
                    $adsX[$i] = $livejasminX[$a];
                    $adsY[$i] = $livejasminY[$a];
                if($ImpLivejasmin != 0){
                    $Min[$i] = min($livejasminY);
                }
                //exo   
                    global $exo;
                    global $exoX;
                    global $exoY;
                    $iframeCountExo = count($exo) - 1;
                    $a = rand(0, $iframeCountExo);
                $i++;   
                $ads[$i] = $exo[$a];
                    $adsX[$i] = $exoX[$a];
                    $adsY[$i] = $exoY[$a];
                if($ImpExo != 0){
                    $Min[$i] = min($exoY);
                }

                //nasty dollars
                    global $ND;
                    global $NDX;
                    global $NDY;
                    $iframeCountND = count($ND) - 1;
                    $a = rand(0, $iframeCountND);
                $i++;   
                $ads[$i] = $ND[$a];
                    $adsX[$i] = $NDX[$a];
                    $adsY[$i] = $NDY[$a];
                if($ImpND != 0){
                    $Min[$i] = min($NDY);
                }

                //amazon.com
                    global $amazon;
                    global $amazonX;
                    global $amazonY;
                    $iframeCountAmazon = count($amazon) - 1;
                    $a = rand(0, $iframeCountAmazon);
                $i++;   
                $ads[$i] = $amazon[$a];
                    $adsX[$i] = $amazonX[$a];
                    $adsY[$i] = $amazonY[$a];
                if($ImpAmazon != 0){
                    $Min[$i] = min($amazonY);
                }
            }

I really have no clue what could be wrong... 我真的不知道有什么问题...

EDIT: extending the time limit is not a solution in this case, this code can and should always be executed within a few miliseconds. 编辑:在这种情况下,延长时间限制不是解决方案,此代码可以并且应该始终在几毫秒内执行。

Increase the time limit of your PHP Script 增加您的PHP脚本的时间限制

<?php
set_time_limit(0);

You may have no error but the error mean you reached the default max_execution_time. 您可能没有任何错误,但是该错误意味着您已达到默认的max_execution_time。

You can update this value. 您可以更新此值。

Use this: 用这个:

 ini_set('max_execution_time', 300); //300 seconds = 5 minutes

Give time in second, whatever you whant 随便你想一想

Or 要么

set_time_limit(0); //no limit

0 - Means no limit 0-表示无限制

Example: 例:

<?php

set_time_limit(20);

while ($i<=10)
{
        echo "i=$i ";
        $i++;
}

?>

To limit the maximum execution time use set_time_limit($seconds) . 要限制最大执行时间,请使用set_time_limit($seconds) If it is set $seconds to zero, no time limit is imposed on it . 如果将$ seconds设置为零,则没有时间限制。 So just try to add set_time_limit(0) at the beginning of your script and script will work till the end. 因此,只需尝试在脚本的开头添加set_time_limit(0) ,脚本将一直工作到结尾。 But if user's browser disconnects due to browser timeout your script could be halted, so you need to add ignore_user_abort(true) at the beginning of the script to ignore it and work exactly till the end of the script 但是,如果用户的浏览器由于浏览器超时而断开连接,则您的脚本可能会暂停,因此您需要在脚本的开头添加ignore_user_abort(true)来忽略它,并在脚本结束之前完全工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM