473,804 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Large Array Problem

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><bo dy>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
Jul 17 '05 #1
2 2605
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" <ma**********@y ahoo.com> wrote in message
news:5f******** *************** ***@posting.goo gle.com...
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><bo dy>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

Jul 17 '05 #2
"Mark" <ma**********@y ahoo.com> wrote in message
news:5f******** *************** ***@posting.goo gle.com...
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><bo dy>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?


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.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6564
by: guillaume | last post by:
I have to read and process a large ASCII file containing a mesh : a list of points and triangles. The file is 100 MBytes. I first tried to do it in memory but I think I am running out of memory therefore I decide to use the shelve module to store my points and elements on disks. Despite the fact it is slow ... Any hint ? I think I have the same memory problem but I don't understand why since my aPoint should be removed by the gc.
2
3504
by: xain | last post by:
HtmlString includes a web page, and soon it is converted to Html file. In the web page, they are images, and some of them are large. They are so large, in fact they are going to destroy my Tables, so I need to resize these images. I write a Function to do this job. Resizeimage(HtmlString) Function Resizeimage(ConStr) Dim TempStr,Re,Matches,Match,Tempi,TempArray
0
6474
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6, 'b_id' => 9, 'c_id' => 3,
5
2723
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied? Thanks in advance. David
3
4171
by: meltedown | last post by:
Normally, if I use $result=print_r($array,TRUE); print_r prints nothing and $result is equal to the readable array. However, if $array is very large, print_r prints the array and returns nothing. Is this correct ? I don't see anything about this in the the manual. I have tried limiting the size to array to see exactly how large the
7
21266
by: ultr | last post by:
I need a large 3D array of structures: struct s { char a; int b; }; s s_array; s_array is declared as global.
1
2262
by: Adam Hartshorne | last post by:
Hi, I have the following problem, I have used the boost library ( boost::multi_array<float,2>) of size X by X. I initialise this using the following line typedef boost::multi_array<float, 2> array_type; array_type D(boost::extents); This works fine up to a size of 5000 x 5000 then my program crashes at
11
11033
by: shreesh | last post by:
I want to use an array of size greater than ARRAY but am getting an array size too large error. I am using a BC 3.1 on msdos ver 5.1.2600 on XP. How can i get around this simple but irritating problem.
16
3820
by: danieleghisi | last post by:
Hello I'm writing a small programme to look for some particular integer sets (homometric sets), and each one of this sets is a unsigned long long (e.g. {1, 2, 4, 7} --1001011=75). I need to have a very long list of sets of this kind, so I declared a #define MAXS = 397148160 static unsigned long long set;
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10354
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.