473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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><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
Jul 17 '05 #1
2 2584
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**********@yahoo.com> wrote in message
news:5f**************************@posting.google.c om...
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

Jul 17 '05 #2
"Mark" <ma**********@yahoo.com> wrote in message
news:5f**************************@posting.google.c om...
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?


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
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...
2
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,...
0
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,...
5
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?...
3
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...
7
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
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>...
11
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...
16
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.