0

I've noticed a strange behaviour in XAMPP v3.3.2 with the PHP memory limit settings. My computer has Windows 10 installed and I have 8GB of memory. In my php.ini file the memory limit is set to 1024M. I also made this basic php file for testing:

<?php

echo ini_get('memory_limit');
exit;
?>

Running this file with different command line parameters, these are the outputs that I am getting:

php -d memory_limit=512M test.php outputs 512M
php -d memory_limit=2048M test.php outputs 2048M
php -d memory_limit=4096M test.php outputs the following error message:

PHP Fatal error:  Allowed memory size of 262144 bytes exhausted (tried to allocate 341351 bytes) in Unknown on line 0

Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 341351 bytes) in Unknown on line 0

php -d memory_limit=5000M test.php outputs 5000M but I still believe that it is not using 5000M of memory (runned some extended tests populating arrays with numbers, and both the test with 2048M set and with 5000M set exits at the same number, with the same message:

PHP Fatal error:  Out of memory (allocated 1457258496) (tried to allocate 134217728 bytes) in C:\xampp\htdocs\test\extended_test.php on line 733

Fatal error: Out of memory (allocated 1457258496) (tried to allocate 134217728 bytes) in C:\xampp\htdocs\test\extended_test.php on line 733


I've stumbled upon this when trying to allocate more memory to a script that should run on my computer. Any ideas what could be causing this?

9
  • 1
    memory_limit of -1 disables the limit, use with caution. Commented Jan 9, 2019 at 18:56
  • 2
    Generally, if you're mucking about with really high memory limits, there's something in your script to fix, like a loop that's not cleaning up after itself. Commented Jan 9, 2019 at 18:56
  • @ceejayoz I am working on a script, strictly for personal use, in which I am implementing a minimax tree, and I am trying to push the depth limits as far as I can. Commented Jan 9, 2019 at 18:59
  • @Devon I know about this, but I wouldn't want to use it, if not REALLY neccessary Commented Jan 9, 2019 at 18:59
  • 1
    There's nothing inherently wrong with disabling the memory limit if you are programming correctly, especially in an isolated environment. If you don't want to disable the limit, it seems like the max supported (from attached dupe) is 4095M. Commented Jan 9, 2019 at 19:03

1 Answer 1

1

Decreasing the ThreadsPerChild from 150 to a lower value solved it for me. Yet I could not explain the connections and background between all the settings in the MPM module, and finally "who" prevents the allocation of more memory.

<IfModule mpm_winnt_module>
    ThreadStackSize 8388608
    ThreadsPerChild 150  # ← try to decrease this value slightly on "Out of Memory" errors under windows.
    MaxConnectionsPerChild   0
</IfModule>
Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me to get rid of the oom-error in the Symfony 5.4 profiler opening the logs. I found the mpm_winnt_module-section in [...]\apache\conf\extra\httpd-mpm.conf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.