Prevent my script from using so much memory?
I have a script which lists all possible permutations in an array, which,
admittedly, might be used instead of a wordlist. If I get this to work,
it'll be impossible to not get a hit eventually unless there is a limit on
attempts.
Anyway, the script obviously takes a HUGE amount of memory, something
which will set any server on fire. What I need help with is finding a way
to spread out the memory usage, something like somehow resetting the
script and continuing where it left off by going to another file or
something, possibly by using Sessions. I have no clue.
Here's what I've got so far:
<?php
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '0');
$possible = "abcdefghi";
$input = "$possible";
function string_getpermutations($prefix, $characters, &$permutations)
{
if (count($characters) == 1)
$permutations[] = $prefix . array_pop($characters);
else
{
for ($i = 0; $i < count($characters); $i++)
{
$tmp = $characters;
unset($tmp[$i]);
string_getpermutations($prefix . $characters[$i],
array_values($tmp), $permutations);
}
}
}
$characters = array();
for ($i = 0; $i < strlen($input); $i++)
$characters[] = $input[$i];
$permutations = array();
print_r($characters);
string_getpermutations("", $characters, $permutations);
print_r($permutations);
?>
Any ideas? :3
No comments:
Post a Comment