•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 427,674 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,258 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3661 | Replies: 1
![]() |
•
•
Join Date: Jun 2004
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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:
[php]
<?
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);
?>
[/php]
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.
What is going on?
Thanks,
Mark
[php]
<?
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);
?>
[/php]
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.
What is going on?
Thanks,
Mark
Last edited by cscgal : Jun 10th, 2004 at 2:05 am.
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 4
How much memory do you have on the server? I have two servers, one with 128MB, and another with 512MB, and it runs fine. I don't know off hand if there's a PHP restriction on array sizes, but I know it must depend on your memory. Also, if you're trying to initialize a large array, consider using array_fill():
$array1 = array_fill(0, 160000, $value1);
$array1 = array_fill(0, 160000, $value1);
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Array problem (C++)
- large 2d array (C++)
- Large array allocation in VB (Visual Basic 4 / 5 / 6)
- class array problem! (C++)
- C++ help with student array problem (C++)
- i have problem with array plz help (Java)
Other Threads in the PHP Forum
- Previous Thread: How do i get other webpage and parse !
- Next Thread: Reseller script



Linear Mode