Please bear with me, as I am a bit new to this. I have a page that calls another page after a form is submitted. The new page contains a lengthy php loop which runs before the page is displayed. The problem is, the server sends a 500 error before the loop has time to finish. I have economy shared linux hosting with GoDaddy, and they don't allow me access to error logs. I am pretty sure it is not a memory issue. I suspect that apache is simply timing out. I have shortened the loop and it works fine, so I am sure that there is nothing wrong with the code, but I would like to know if there are any tricks to code the loop better, or trick apache into giving the loop more time, or anything to make this work. Thanks in advance, and here is the code:
Some variables before the loop starts:
$usernum1 = $_POST['num1'];
$usernum2 = $_POST['num2'];
$usernum3 = $_POST['num3'];
$usernum4 = $_POST['num4'];
$usernum5 = $_POST['num5'];
$usernum6 = $_POST['num6'];
$usernum7 = $_POST['num7'];
$usernumbers = array($usernum1, $usernum2,
$usernum3, $usernum4,
$usernum5, $usernum6,
$usernum7);
sort($usernumbers, SORT_NUMERIC);
$i = 0;
$counter = 0;
set_time_limit(0);
$input = range(1, 49);
Here is the loop:
do {
$rand_keys = array_rand($input, 7);
sort($rand_keys, SORT_NUMERIC);
if ($input[$rand_keys[0]] == $usernumbers[0] &&
$input[$rand_keys[1]] == $usernumbers[1] &&
$input[$rand_keys[2]] == $usernumbers[2] &&
$input[$rand_keys[3]] == $usernumbers[3] &&
$input[$rand_keys[4]] == $usernumbers[4] &&
$input[$rand_keys[5]] == $usernumbers[5] &&
$input[$rand_keys[6]] == $usernumbers[6])
{
$i = 1;
}
$counter = $counter + 1;
} while ($i == 0);
You can see the that the loop ends when $i == 1, and $i is assigned 1 when all numbers match. I should also mention that I added max_execution_time = 1000 to my php5.ini file on the server, and when I check phpinfo, it seems to have taken effect.
And That's IT! Not very complex. If anyone can help me figure out some trick, or better way, please, please help, as I have busted my brain for 2 days on this.
I just need the loop to have more time to finish. Thanks again in advance :-)
EDIT: For those who want to see the script working, I have it for a lottery that only has SIX numbers, is easier to win, and doesn't timeout. Go here and MAKE SURE TO select the top option (Lotto 649). http://diablogosse.com/test/lottosims.php
EDIT2: Sorry if this comes across badly, but I just wanted to clarify something after quite a few posts. My question is not "Why in God's name would I WANT to do this??". The question is more like: "How can I make what I WANT to do work.". ;-)
Chris