| | |
Storing and Retrieving Number String/Array
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
LOL, I just checked my memory it is at 128MB
(hence 134217728 bytes)
This is just for localhost at the moment so im not too worried if it cant work on the internet, its more for a home requirement for now.
It is just a loop that declares arrays and I think it declares too many but I need it to declare an x amount.
its like:
Now I dont know how many times each loop goes for, depends on the requirements but it is ALOT so I dont know what to do at the moment?
Also on the 128MB thing what happens if I changed it to 99999.
Will the calculation work at the risk of blowing up my computer? or just freezing IE?
Thanks, Regards X
(hence 134217728 bytes)This is just for localhost at the moment so im not too worried if it cant work on the internet, its more for a home requirement for now.
It is just a loop that declares arrays and I think it declares too many but I need it to declare an x amount.
its like:
PHP Syntax (Toggle Plain Text)
for($i=0;$i<999999999999;$i++) { for($i=0;$i<999999999999;$i++) { $alpha[] = --$i . " " . $i . " " . ++$i; } }
Now I dont know how many times each loop goes for, depends on the requirements but it is ALOT so I dont know what to do at the moment?
Also on the 128MB thing what happens if I changed it to 99999.
Will the calculation work at the risk of blowing up my computer? or just freezing IE?
Thanks, Regards X
Last edited by OmniX; Jun 18th, 2008 at 8:58 am.
I thought so 
How about storing everything in a file or database instead of in memory ?
You computer is fine (with windows 2000 or better. (or linux).
With 99999 the code will still crash:
Each string is 5 bytes (1 byte for each character)
the inner loop loops 99.999 times.
The outher loop also
So memory required (in MB) == ((99.999 * 99.999 * 5) /1024) /1024 = 9536 MB

•
•
•
•
Now I dont know how many times each loop goes for, depends on the requirements but it is ALOT so I dont know what to do at the moment?
•
•
•
•
Also on the 128MB thing what happens if I changed it to 99999.
Will the calculation work at the risk of blowing up my computer? or just freezing IE?
With 99999 the code will still crash:
Each string is 5 bytes (1 byte for each character)
the inner loop loops 99.999 times.
The outher loop also
So memory required (in MB) == ((99.999 * 99.999 * 5) /1024) /1024 = 9536 MB
lol..You can increase the execution time limit, by either changing max_execution_time to 0 (in php.ini ) or use set_time_limit(0); in your script.
Ignore this post !
This will crash your browser anyway
Ignore this post !
•
•
•
•
for($i=0;$i<999999999999;$i++) {
for($i=0;$i<999999999999;$i++) {
$alpha[] = --$i . " " . $i . " " . ++$i;
}
}
Last edited by nav33n; Jun 18th, 2008 at 9:10 am.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Well a family friend has told me to construct a program on vary vague requirements.
But it requires at least 5 nested for loops and the iterations come out to something like intializing like 1mil plus arrays but by the end the script it removes like 800,000 of them.
So is this just not possible with php?
Do I have to pass it onto java or learn it myself?
Any possible fixes? Thanks
PS: can I increase "max_execution_time = 30"? Dosent seem to be working when I change the value to like 60/120.
But it requires at least 5 nested for loops and the iterations come out to something like intializing like 1mil plus arrays but by the end the script it removes like 800,000 of them.
So is this just not possible with php?
Do I have to pass it onto java or learn it myself?
Any possible fixes? Thanks
PS: can I increase "max_execution_time = 30"? Dosent seem to be working when I change the value to like 60/120.
Last edited by OmniX; Jun 18th, 2008 at 9:30 am.
Initializing 1.000.000 arrays shouldn't be a problem (as long as they aren't bigger then 134 bytes), but what you asked:
will result in 99.999 * 99.999 loops, which is something like 10.000.000.000 loops.
So the answer is: yes, a million arrays in the memory are possible
PHP Syntax (Toggle Plain Text)
for (0 to 99.999) for (0 to 99.999)
So the answer is: yes, a million arrays in the memory are possible
Depends on how big your array is.
Let's say that the string in the array looks like this:
(NOTE: I don't know exactly how PHP memory works with memory, so it might also be 6 bytes as in C and C++, where the last byte represents an 'end of string' character)
so you have 128 MB of memory, but you want to keep some of that available for other programs like windows etc. So let's say we can use half of it == 64 MB. That would lead to the following calculation:
(64*1024^2) / 5 = 13.421.772 elements for your array.
So to keep it on the safe side: max = 10 million
Let's say that the string in the array looks like this:
1 2 3 In theory this requires 5 bytes of memory. (3 numbers and two spaces)(NOTE: I don't know exactly how PHP memory works with memory, so it might also be 6 bytes as in C and C++, where the last byte represents an 'end of string' character)
so you have 128 MB of memory, but you want to keep some of that available for other programs like windows etc. So let's say we can use half of it == 64 MB. That would lead to the following calculation:
(64*1024^2) / 5 = 13.421.772 elements for your array.
So to keep it on the safe side: max = 10 million
Last edited by niek_e; Jun 18th, 2008 at 9:40 am.
![]() |
Other Threads in the PHP Forum
- Previous Thread: inserting into selected fields
- Next Thread: PHP/MySQL errors:-mysql_num_rows(): and mysql_fetch_array():
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax alerts apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display download dynamic echo email error file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop overwrite parse paypal pdf php problem query radio random recursion redirect regex remote script search securephp server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube






