Connecting Tech Pros Worldwide Help | Site Map

Large Array Problem

  #1  
Old July 17th, 2005, 06:44 AM
Mark
Guest
 
Posts: n/a
I am using PHP 4.3.5. I am having a problem in which my script is
crashing when it is using a large array. I have simplified the
problem down to the following example:

<?
set_time_limit(0);
echo("<html><body>test<br>");
$array1 = array();
$value1 = 1;
for ($index = 0; $index < 160000; $index++)
{
$array1[] = $value1;
}
for($index = 0; $index < 100; $index++)
{
echo("index = $index, value = $array1[$index]<br>");
}
echo("done<br>");
echo("</body></html>");
exit(0);
?>

If I run the above code it crashes with nothing displayed to the
screen. If I change the loop to go to 80000 instead of 160000 then it
works fine.

Also, I can keep the loop setting at 160000 but change the line:
$array1[] = $value1;
to instead read
$array1[] = 1;
and then it also works fine.

Why does it fail when there are 160000 elements in the array that are
set with a variable?

Thanks,
Mark
  #2  
Old July 17th, 2005, 06:44 AM
michel
Guest
 
Posts: n/a

re: Large Array Problem


Try:
print("index = $index, value = $array1[$index]<br>");flush();

and see where it goes wrong exactly. it will give you the output directly.

Mich

"Mark" <marktmp87342@yahoo.com> wrote in message
news:5f18923b.0406092155.5efa561f@posting.google.c om...[color=blue]
> I am using PHP 4.3.5. I am having a problem in which my script is
> crashing when it is using a large array. I have simplified the
> problem down to the following example:
>
> <?
> set_time_limit(0);
> echo("<html><body>test<br>");
> $array1 = array();
> $value1 = 1;
> for ($index = 0; $index < 160000; $index++)
> {
> $array1[] = $value1;
> }
> for($index = 0; $index < 100; $index++)
> {
> echo("index = $index, value = $array1[$index]<br>");
> }
> echo("done<br>");
> echo("</body></html>");
> exit(0);
> ?>
>
> If I run the above code it crashes with nothing displayed to the
> screen. If I change the loop to go to 80000 instead of 160000 then it
> works fine.
>
> Also, I can keep the loop setting at 160000 but change the line:
> $array1[] = $value1;
> to instead read
> $array1[] = 1;
> and then it also works fine.
>
> Why does it fail when there are 160000 elements in the array that are
> set with a variable?
>
> Thanks,
> Mark[/color]


  #3  
Old July 17th, 2005, 06:44 AM
Chung Leong
Guest
 
Posts: n/a

re: Large Array Problem


"Mark" <marktmp87342@yahoo.com> wrote in message
news:5f18923b.0406092155.5efa561f@posting.google.c om...[color=blue]
> I am using PHP 4.3.5. I am having a problem in which my script is
> crashing when it is using a large array. I have simplified the
> problem down to the following example:
>
> <?
> set_time_limit(0);
> echo("<html><body>test<br>");
> $array1 = array();
> $value1 = 1;
> for ($index = 0; $index < 160000; $index++)
> {
> $array1[] = $value1;
> }
> for($index = 0; $index < 100; $index++)
> {
> echo("index = $index, value = $array1[$index]<br>");
> }
> echo("done<br>");
> echo("</body></html>");
> exit(0);
> ?>
>
> If I run the above code it crashes with nothing displayed to the
> screen. If I change the loop to go to 80000 instead of 160000 then it
> works fine.
>
> Also, I can keep the loop setting at 160000 but change the line:
> $array1[] = $value1;
> to instead read
> $array1[] = 1;
> and then it also works fine.
>
> Why does it fail when there are 160000 elements in the array that are
> set with a variable?[/color]

What do you mean by "crashing?" Did Apache (or whatever) blow up or did you
just get a blank page? On computers with small amount of memory, PHP can
indeed crash the server.


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Problem When Index Value is Nothing Robert Bevington answers 3 June 27th, 2008 09:14 PM
Large 2D Array Problem Adam Hartshorne answers 1 March 24th, 2006 11:55 AM
Fastest way to pass large array to and from COM apm answers 5 November 17th, 2005 09:26 AM
Array problem gouqizi.lvcha@gmail.com answers 11 November 14th, 2005 11:50 PM