Running out of memory.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Running out of memory.

Post by penguinboy »

I have a script that needs to loop 11390625x's.
But i've run into a problem with
1) the script times out
2) the script runs out of memory

I can fix it timeing out but I don't know what to do about memory.
I've given php 900 meg to use, but thats not enough. :cry:

So is there anything I can do with the code to make it free memory?

[syntax=php]$num[1] = 1;
$num[2] = 2;
$num[3] = 3;
$num[4] = 4;
$num[5] = 5;
$num[6] = 6;
$num[7] = 7;
$num[8] = 8;
$num[9] = 9;
$num[10] = "a";
$num[11] = "b";
$num[12] = "c";
$num[13] = "d";
$num[14] = "e";
$num[15] = "f";
$x=1;
$f=1;
$e=1;
$d=1;
$c=1;
$b=1;
$a=1;
$count=1;
while($x==1){
$arr[$count] = $num[$a].$num[$b].$num[$c].$num[$d].$num[$e].$num[$f];
if($f==15){$f=0; $e++;}
if($e==15){$e=0; $d++;}
if($d==15){$d=0; $c++;}
if($c==15){$c=0; $b++;}
if($b==15){$b=0; $a++;}
if($a==15){$x=0;}
$f++;
$count++;
}[/syntax]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what's the purpose of that?
(not what the snippet does but why you need $arr)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

You have BBcode and Smiles disabled in your Profile, i believe. :wink:

I suggest not putting a memory limit on php, it just gets annoying when you have an php app that needs more than you allowed.

Or do what i would do just set the execution time high, and a new processor/mem stick. 8)
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

[quote="volka"]what's the purpose of that?
(not what the snippet does but why you need $arr)[/quote]

I was try store 11390625 combinations of numbers and letters in an array.
But I decieded that probably wouldn't work.

[quote="Oromian"]You have BBcode and Smiles disabled in your Profile, i believe. :wink:

I suggest not putting a memory limit on php, it just gets annoying when you have an php app that needs more than you allowed.

Or do what i would do just set the execution time high, and a new [url=http://ebay.ca]processor/mem stick[/url]. 8)[/quote]

Yep I do.
I'll try not putting a memory limit.
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

surely the only reason for doing that is hacking a lowercase 6 character password somewhere :roll:

wouldn't it be better to just step incrementally from zero and define a character instance resultant from the remainder of a powered base sixteen step and just use the returned string once before overwriting - at least the entire array would never need to be held in memory.

as there is a slight chance that you only want it to output possible combinations of hexadecimel colour references......

Code: Select all

ini_set('max_execution_time',600);
$strt = 0;
$stp = 16777216;
while($strt++ < $stp)
	{
	$str = substr('00000'.dechex($strt),-6);
	echo $str.' * ';
	}
subnote: I echoed it as putting 12.58Meg+ into memory ('specially as a defined index array) is a trifle daft imo
Post Reply