1

I have a pretty "unconventional" setup that looks like this:

I have a VMware virtual machine running Ubuntu Desktop 12.10 with networking set to bridge. Installed inside the VM is nginx, php-fpm, php-cli and MySQL. PHP is 5.4.10.

I have a folder containing all the files for the application I am working on in the host (Windows 7). This folder is then made available as a network share.

The virtual machine then mounts the windows share via samba into a directory. This directory is then served by nginx and php-fpm. So far, everything has worked fine.

I have a script that I run via the php CLI to help me build and process some files. Previously, this script has worked fine on my windows host. However, it seems to throw cannot allocate memory errors when I run it in the Ubuntu VM. The weird thing is that it's sporadic as well and does not happen all the time.

user@ubuntu:~$ sudo /usr/local/php/bin/php -f /www/app/process.php 

Warning: require_once(/www/app/somecomponent.php): failed to open stream: Cannot allocate memory in /www/app/loader.php on line 130

Fatal error: require_once(): Failed opening required '/www/app/somecomponent.php' (include_path='.:/usr/local/php/lib/php') in /www/app/loader.php on line 130

I have checked and confirmed the following:

  • /www/app/somecomponent.php definitely exists.

  • The permissions for /www and all files and sub directories inside are set to execute and read+write for owner, group and others.

  • I have turned off APC after reading this question to see if APC is the cause, but the problem still persists after doing so.

  • php-cli is using the same php.ini as php-fpm, which is located in /etc/php/php.ini.

  • memory_limit in php.ini is set to 128M (default) which seems plenty for the app.

  • Even after increasing the memory limit to 256M, the error still occurs.

  • The VM has 2GB of memory.

I have been googling to find out what causes cannot allocate memory errors, but have found nothing useful. What could be causing this problem?

Community
  • 1
  • 1
F21
  • 32,163
  • 26
  • 99
  • 170
  • How much memory does your VM itself have, though? – Ry- Dec 26 '12 at 23:48
  • The VM has 2GB of memory. – F21 Dec 26 '12 at 23:51
  • Is anything else running taking up an excessive amount of memory? – Ry- Dec 26 '12 at 23:52
  • Not from what I can see. The swap isn't even being used because there is more than enough memory for all running processes. – F21 Dec 26 '12 at 23:54
  • Does it do anything before requiring `somecomponent.php`? – Ry- Dec 26 '12 at 23:56
  • Yes it does, but those things don't seem to throw up any errors. The script is pretty complex and uses the autoloader (`loader.php`) to load classes. – F21 Dec 27 '12 at 00:00
  • Well, they may not throw up any errors themselves, but maybe they very nearly exhaust the existing memory? I’m not sure :P – Ry- Dec 27 '12 at 00:04
  • Not very likely it would be hitting memory limits though (because it happens when I increase the `memory_limit` to `256M`. Having said that, sometimes, instead of throwing on the `require_once`, it throws the same `cannot allocate memory error` on a `file_get_contents` to load a 10kb JS file. I have a feeling that perhaps being a network share, something is making the files locked or unreadable occasionally. – F21 Dec 27 '12 at 00:08
  • Oh, and the strange thing is that `php-fpm` is totally fine. It only occurs when running scripts via `php-cli`. – F21 Dec 27 '12 at 00:10

1 Answers1

0

It turns out this was a problem with my windows share. Perhaps because Windows 7 is a client OS, it is not tuned to serve large amounts of files frequently (which is happening in my case).

To fix, set the following keys in the registry:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache to 1

HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size to 3

I have been running my setup with these new settings for about a week and have not encountered any memory allocation errors since making the change.

F21
  • 32,163
  • 26
  • 99
  • 170