Jump to content

[Solved] Problem allocating memory


prestacoco

Recommended Posts

Hi,

At the prestashop root, I have a test.php script with this content

require('./config/config.inc.php');

error_reporting(E_ALL);
ini_set("memory_limit", '2048M');
ini_set('default_socket_timeout', -1);
set_time_limit(0);
ini_set('display_errors', 'on');

$size = pow(2, 18); //2^18 = 262144, 2^17 = 131072

$startTime = microtime(true);

$array = array();
for ($key = 0, $maxKey = $size - 1; $key <= $maxKey; ++$key) {
	$line = ['id' => 55, 'ref_1' => "JKJKJ798798", 'ref_2' => "AKUYT798798", 'id_test' => "TEST798798", 'id_category' => 18, 'desc_long' => "L'investissement immobilier s'avère être une valeur sûre pour de nombreux investisseurs. Que ce soit pour générer des revenus locatifs réguliers ou pour réaliser une plus-value à long terme, la pierre est un placement attractif. Cependant, avant de se lancer, il est essentiel d'étudier attentivement le marché local, de définir un budget précis et d'envisager les éventuels frais liés à l'achat, à la gestion locative et à la fiscalité. L'accompagnement d'un professionnel de l'immobilier peut s'avérer précieux pour prendre les meilleures décisions.", 'desc_short' => "L'investissement immobilier s'avère être une valeur sûre pour de nombreux investisseurs. Que ce soit pour générer des revenus locatifs réguliers ou pour réaliser une plus-value à long terme, la pierre est un placement attractif. Cependant, avant de se lancer, il est essentiel d'étudier attentivement le marché local, de définir un budget précis et d'envisager les éventuels frais liés à l'achat, à la gestion locative et à la fiscalité. L'accompagnement d'un professionnel de l'immobilier peut s'avérer précieux pour prendre les meilleures décisions.", 'wholesale_price' => 1028.510000, 'title' => "Générer des revenus locatifs réguliers", 'personnalisable' => 0, 'statutnum' => 1, 'nb_vu' => 150, 'datecrea' => "2024-09-18 09:25:00", 'dateupd' => "2024-09-18 09:25:00"];
    $array[$key] = $line;
}

$endTime = microtime(true);

echo 'Inserting ', $size, ' good elements took ', $endTime - $startTime, ' seconds', "\n";


I run it in command line "php test.php" and I have this error 

Quote

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

Fatal error: Out of memory (allocated 195039232) (tried to allocate 20480 bytes) in /home2/stocketik/public_html/test.php on line 16

No matter if I increase memory_limit, I always get the error.
If I set memory_limit to 128M I have the following error "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)" which makes sense.

The strange thing is that if I remove the require line the script runs successfully.

Has anyone ever encountered this problem? How can I solve it ?

Removing the require line is not the solution. I just made this script as a POC and to simplify my problem. In my real scenario I have a script which makes a database request (a select using Db::getInstance()->executeS($sql_select)) and it crashs.

 For further information, I'm using PS 1.7 and PHP 7.0. I also tried with PHP 8 and same problem.

Edited by prestacoco (see edit history)
Link to comment
Share on other sites

4 minutes ago, ps8modules said:

I have completed the answer. See if it's out of range.

Before the require, memory_limit is 4096M (I think my hosting provider increased the value) and after the require I echo the ini_get('memory_limit') and it continues to be 4096M.

  • Like 1
Link to comment
Share on other sites

Thanks for your help. I was contacted by my hosting provider and he explained me that there was a shell restriction and he removed this restriction.
It was not related to memory_limit.

I think this page https://support.cpanel.net/hc/en-us/community/posts/19163447287703-Max-Memory-for-a-User can give more information about the problem I encountered. As a shell user, I was limited to 200M of RAM for a process so even if I was increasing memory_limit it did not solve my problem.

Hope this can help other users encountering the same problem.

Edited by prestacoco
adding information (see edit history)
  • Like 1
Link to comment
Share on other sites

21 minutes ago, prestacoco said:

Thanks for your help. I was contacted by my hosting provider and he explained me that there was a shell restriction and he removed this restriction.
It was not related to memory_limit.

Please mark this topic as SOLVED

  • Like 1
Link to comment
Share on other sites

  • prestacoco changed the title to [Solved] Problem allocating memory

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...