To cycle on a huge amount
PHP
$SCode=$_POST['SCode'];
$ECode=$_POST['ECode'];
for($p=$SCode;$p<$ECode;$p++)
{
$dbResult= $dbHandle->query("
SELECT Code
FROM Mashaghel
Where Code=" . $p . "");
if(!isset($Mashaghel[0]["Code"]) || empty($Mashaghel[0]["Code"]))
{
$errorCode.=$p."،";
}
}
echo $errorCode."does not existed!";
Start this with
$_POST['SCode']='010100100101002084';
$_POST['ECode']='010100100101002087';
but it didn't work and says an error Maximum execution time of 60 seconds exceeded
So far the difference between 010100100101002084
and is 010100100101002087
only 3.
Why do infinite for a loop !?
Please help me
The reason your script takes so long might be a request inside your loop. You can try adding "LIMIT 1" to your query so that it only processes one row, or changes 1 to the number of rows you need to process. If you still want your script to be able to execute longer information, see this in more detail. By default PHP exits the script after 60 seconds to prevent the scripts from hanging. In php.ini there is a value that determines the maximum running time of a PHP script - it is called max_execution_time
. You can also change this value for a specific script function to running set_time_limit()
( docs ).
source to share
break the for limit by two numbers. for example think your limit for loop limit is 1000, a break of 100,10 makes 2 nested for loops.
and for some numbers that are not divisible you can do some of the loops one after the other, for example think your number is 11 do this 5 + 6 like you have 2 for loops that run exactly one after the other with exact code in a loop. also you can check the while loop.
In the end, I don't think this is a solution, it's just a way to fix your problem temporarily.
source to share