Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8812 > unrolled thread

Fatal error!

Started bygb <no@yahoo.it>
First post2013-03-24 11:43 +0100
Last post2013-03-24 14:34 +0100
Articles 5 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  Fatal error! gb <no@yahoo.it> - 2013-03-24 11:43 +0100
    Re: Fatal error! Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-24 08:04 -0400
    Re: Fatal error! Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-03-24 14:00 +0100
      Re: Fatal error! Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-24 09:05 -0400
        Re: Fatal error! Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2013-03-24 14:34 +0100

#8812 — Fatal error!

Fromgb <no@yahoo.it>
Date2013-03-24 11:43 +0100
SubjectFatal error!
Message-ID<514ed8b4$0$37122$4fafbaef@reader1.news.tin.it>
Hi,
I'm a newbye of PHP, why it gives me this error:

Fatal error: Maximum execution time of 60 seconds exceeded in 
C:\xampp\htdocs\ord.php on line 30

Is there a time limits?

This is the script that run locally on xampp:

<?php

$nmin_rand=1;
$nmax_rand=100000;
$l_arr=100000;
$n=0;

$num_estr=array();
$num_copia=array();

//inizializza array lungo $l_arr

echo "<br>";
for ($i=0; $i<$l_arr; $i++){

     $num_estr[$i]=rand($nmin_rand,$nmax_rand);

     echo " ".$num_estr[$i]." ";

     }


// Ordinamento

$flag=true;

do{
      $flag=false;

      for ($i=0; $i<$l_arr-1; $i++)
         if ($num_estr[$i]>$num_estr[$i+1]){

             $temp=$num_estr[$i];
             $num_estr[$i]=$num_estr[$i+1];
             $num_estr[$i+1]=$temp;

             $flag=true;

             $n++;

             }

}while($flag);

//stampa array ordinato lungo $l_arr

echo "<br>";
for ($i=0; $i<$l_arr; $i++){

     echo " ".$num_estr[$i]." ";

     }

echo "<br>Numero scambi : ".$n;

?>

















[toc] | [next] | [standalone]


#8813

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-24 08:04 -0400
Message-ID<kimq13$taq$1@dont-email.me>
In reply to#8812
On 3/24/2013 6:43 AM, gb wrote:
>
> Hi,
> I'm a newbye of PHP, why it gives me this error:
>
> Fatal error: Maximum execution time of 60 seconds exceeded in
> C:\xampp\htdocs\ord.php on line 30
>
> Is there a time limits?
>
> This is the script that run locally on xampp:
>
> <?php
>
> $nmin_rand=1;
> $nmax_rand=100000;
> $l_arr=100000;
> $n=0;
>
> $num_estr=array();
> $num_copia=array();
>
> //inizializza array lungo $l_arr
>
> echo "<br>";
> for ($i=0; $i<$l_arr; $i++){
>
>      $num_estr[$i]=rand($nmin_rand,$nmax_rand);
>
>      echo " ".$num_estr[$i]." ";
>
>      }
>
>
> // Ordinamento
>
> $flag=true;
>
> do{
>       $flag=false;
>
>       for ($i=0; $i<$l_arr-1; $i++)
>          if ($num_estr[$i]>$num_estr[$i+1]){
>
>              $temp=$num_estr[$i];
>              $num_estr[$i]=$num_estr[$i+1];
>              $num_estr[$i+1]=$temp;
>
>              $flag=true;
>
>              $n++;
>
>              }
>
> }while($flag);
>
> //stampa array ordinato lungo $l_arr
>
> echo "<br>";
> for ($i=0; $i<$l_arr; $i++){
>
>      echo " ".$num_estr[$i]." ";
>
>      }
>
> echo "<br>Numero scambi : ".$n;
>
> ?>
>

http://www.lmgtfy.com/?q=%22Fatal+error%3A+Maximum+execution+time%22+php


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8814

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2013-03-24 14:00 +0100
Message-ID<kimtdj$a4$1@news.albasani.net>
In reply to#8812
gb schrieb:

> Fatal error: Maximum execution time of 60 seconds exceeded in 
> C:\xampp\htdocs\ord.php on line 30
> Is there a time limits?

Yes there is. But you can change that:
http://www.php.net/set-time-limit

> This is the script that run locally on xampp:
[...]

So you are basically creating an array of 100000 elements, each being a 
random number in the range 1 to 100000. That means, statistically, each 
number in the given range would appear once. There's a simpler way to do 
that:

$data = range( 1, 100000 );
shuffle( $data );
echo implode( ', ', $data );

Then you want to sort the array. I assume this is some kind of exercise 
and you do this for learning purposes. You have chosen a sorting 
algorithm which is quite time-consuming, i.e. not very efficient, so 
it's no wonder that your script times out, especially when you use such 
a large array.

You can improve the algorithm a bit: After the first run of the for-loop 
the largest number will have moved to the end of the array, in other 
words, it will already be where it's supposed to be. Therefore, in the 
next round, you don't need to go all the way to the end of the array: 
you can skip the last entry. Likewise, after the second run of the 
for-loop, the second largest number will also be at its final place and 
consequently you can skip the last two elements in the third run. And so 
on. This way, you don't have to pass through the whole array each time 
and your script will run a bit faster. You can achieve this by replacing 
the do-while-loop with another for-loop and you also can get rid of the 
$flag.

But there are many other sorting algorithms -- and much more efficient 
ones. It will be instructive to learn about them and try to implement 
them. And then you can compare them to see which is the fastest.

Greetings,
Thomas

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [next] | [standalone]


#8815

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-24 09:05 -0400
Message-ID<kimtj1$eka$1@dont-email.me>
In reply to#8814
On 3/24/2013 9:00 AM, Thomas Mlynarczyk wrote:
> gb schrieb:
>
>> Fatal error: Maximum execution time of 60 seconds exceeded in
>> C:\xampp\htdocs\ord.php on line 30
>> Is there a time limits?
>
> Yes there is. But you can change that:
> http://www.php.net/set-time-limit
>
>> This is the script that run locally on xampp:
> [...]
>
> So you are basically creating an array of 100000 elements, each being a
> random number in the range 1 to 100000. That means, statistically, each
> number in the given range would appear once. There's a simpler way to do
> that:
>
> $data = range( 1, 100000 );
> shuffle( $data );
> echo implode( ', ', $data );
>

This would note create an array of random numbers.  It will create a 
randomized array of numbers - two entirely different things.

In a random array, duplicates are expected to happen.  That's the nature 
of random numbers.

> Then you want to sort the array. I assume this is some kind of exercise
> and you do this for learning purposes. You have chosen a sorting
> algorithm which is quite time-consuming, i.e. not very efficient, so
> it's no wonder that your script times out, especially when you use such
> a large array.
>

True, quick sort is quite to write - but not so quick in execution.

> You can improve the algorithm a bit: After the first run of the for-loop
> the largest number will have moved to the end of the array, in other
> words, it will already be where it's supposed to be. Therefore, in the
> next round, you don't need to go all the way to the end of the array:
> you can skip the last entry. Likewise, after the second run of the
> for-loop, the second largest number will also be at its final place and
> consequently you can skip the last two elements in the third run. And so
> on. This way, you don't have to pass through the whole array each time
> and your script will run a bit faster. You can achieve this by replacing
> the do-while-loop with another for-loop and you also can get rid of the
> $flag.
>

A minor improvement, but anything helps.

> But there are many other sorting algorithms -- and much more efficient
> ones. It will be instructive to learn about them and try to implement
> them. And then you can compare them to see which is the fastest.
>

Agreed.  And learning about different sorting algorithms is a great 
learning experience in itself.

> Greetings,
> Thomas
>


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8816

FromThomas Mlynarczyk <thomas@mlynarczyk-webdesign.de>
Date2013-03-24 14:34 +0100
Message-ID<kimvcc$4a1$1@news.albasani.net>
In reply to#8815
Jerry Stuckle schrieb:
>> $data = range( 1, 100000 );
>> shuffle( $data );
> This would note create an array of random numbers.  It will create a 
> randomized array of numbers - two entirely different things.
> In a random array, duplicates are expected to happen.  That's the nature 
> of random numbers.

This is, of course, true, but I still consider my suggestion to be 
sufficient for the OP's sorting exercise [1]. On the other hand: a few 
duplicates might be useful to prove that the sorting algorithm can deal 
with them.

Greetings,
Thomas

[1] The rand() function is -- like any deterministic algorithm -- not 
truly random either.

-- 
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web