Hi there!
I coded the following code to pick 6 random numbers:

<?

//set_time_limit(30);

$numeros[] = rand(1, 60);

while(count($numeros) < 6) {

$numero = rand(1, 60);

if(array_search($numero, $numeros) === false) {

$numeros[] = $numero;

}

}

?>

It worked fine on my computer (php4.2.2/apache/win), but it's not working on lycos server....The following error is shown:

Fatal error: Maximum execution time of 10 seconds exceeded in megasena.php on line 11

I tried to use the set_time_limit() but the problem was not solved...

Could anyone help me??

Thanx in advance

    the // infront of set time limit make it into a comment.. remove them

      1. If the server is running PHP with safe mode on, then set_time_limit() is disabled (http://www.php.net/set-time-limit - paragraph 3). See if you can get your host to change the configuration at their end.

      2. Who was the idiot who limited script execution to 10 seconds instead of providing decent hosting?

      3. What's your script doing that's taking so long, anyway?

        I know about the comment...Of course when I tested it I did so without the comment!!!

        Well, what the script does is pick 6 numbers (1 thru 60) randomly...Then show the numbers...

        I used array_search to make sure that there is no double entries on the array (numbers must be uniques).

        The host is lycos....you can check my website at http://members.lycos.co.uk/phpmaster

        What really make me mad is that my script is working fine and much faster then 10 secs on my computer....

        Thanx in advance

          You'd be better off using in_array() instead of array_search()...

          If that's all it's doing then it certainly shouldn't be taking 10 seconds. Of course, I've tried following the Lycos links you've provided, and I've so far typed everything you see above, and I'm still waiting for the pages to display ... 🙂 ... still waiting.

          Let's see if I can't think of another way of generating six random numbers 1..60....

          🆒 - you don't need to seed PHP4.2's RNG! (Is Lycos using 4.2? Does that make a difference?)

          Oops, they've both timed out - now we'll never know 🙂

          No idea if it'll be faster, but

          $numbers=range(1,60);
          shuffle($numbers);
          $numbers=array_slice($numbers,0,6);
          

          Will have the desired effect. (Probably be a bit slower, 'cos it's gotta randomise the whole array). Dunno if the description is obsolete, but it still says you need to srand() first to get shuffle() to work.

            For a bit of amusement, here's a version to try that doesn't use array functions at all:

            $numbers=array();
            $c=-1;
            while(count($numbers)<6)
            {	$number=rand(1,60);
            	for($j=0; $j<=$c; ++$j)
            	{	if($numbers[$j]==$number)
            		{	continue 2;
            		}
            	}
            	$numbers[++$c]=$number;
            }
            

            And when lycos's servers have had their rubber bands wound tightly enough...

              hi

              nothing to do with random numbers(!!) but i think in their config lycos have the line

              annoying_adds = On

              If youre in the uk and prepared to use another ISP for uploading etc then id suggest looking at http://www.uklinux.net/ - they are a free isp who give you free webspace with php and perl and mysql. try running the same script on their server.

              i found it useful till i bought webspace of my own.

              btw - i dont work for uklinux.net or anything - just like the service :-)

              vincent fleetwood.

                22 days later

                my program will read a log file with about 30000+ lines. the problem was my program won't be able to finish reading all of the lines and eventually i got an error message CGI Timeout.

                why is this happenning?

                i have tried to set the set_time_limit(1000) but it gives the same outcome.

                plez help

                  i've solved it

                  but I have set the time limit to a big number

                  set_time_limit(1000000)

                  does this setting will create hic-ups to my program?

                    Write a Reply...