Edward
Edward

Reputation: 3081

PHP memory size issue

Hello I need to analyze around 50,063,860 combinations for my fantasy roster. It's 60 pick 6.

I am trying to generate all possible combinations passing the names array to the Math_Combinatorics pearl library:

$n is an array of 60 elements,

$result = $combinatorics->combinations( $n, 6);

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 72 bytes) in /usr/share/php/Math/Combinatorics.php on line 126

Is there anyway to allocate more memory or feed it less entries at one time so it does not crash?

Upvotes: 2

Views: 130

Answers (2)

Asaph
Asaph

Reputation: 162841

You can increase the memory_limit in your php.ini. From the php docs:

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

You can also set this value inline in your script using the ini_set() function or even in an apache virtual host configuration using the php_value directive.

Having said that, it would probably behoove you to refactor your code such that not all the permutations need be in memory at once, thereby drastically reducing your program's memory footprint.

Upvotes: 1

Abdulla Nilam
Abdulla Nilam

Reputation: 38652

You can skip this error by using ini_set('memory_limit', '-1');. This will override default method.

PHP allocated Memory Size

But Note this is not better solution for it. Check this out as well

And Possible Duplicate of Allowed memory size of 33554432 bytes exhausted

Upvotes: 1

Related Questions