I have a bunch of client point of sale (POS) systems that periodically send new sales data to one centralized database, which stores the data into one big database for report generation.
The client POS is based on PHPPOS, and I have implemented a module that uses the standard XML-RPC library to send sales data to the service. The server system is built on CodeIgniter, and uses the XML-RPC and XML-RPCS libraries for the webservice component. Whenever I send a lot of sales data (as little as 50 rows from the sales table, and individual rows from sales_items pertaining to each item within the sale) I get the following error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 54 bytes)
128M is the default value in php.ini
, but I assume that is a huge number to break. In fact, I have even tried setting this value to 1024M, and all it does is take a longer time to error out.
As for steps I've taken, I've tried disabling all processing on the server-side, and have rigged it to return a canned response regardless of the input. However, I believe the problem lies in the actual sending of the data. I've even tried disabling the maximum script execution time for PHP, and it still errors out.
In Drupal 7, you can modify the memory limit in the settings.php file located in your sites/default folder. Around line 260, you'll see this:
Even if your php.ini settings are high enough, you won't be able to consume more than 128MB if this isn't set in your Drupal settings.php file.
When you see the above error - especially if the
(tried to allocate __ bytes)
is a low value, that could be an indicator of an infinite loop, like a function that calls itself with no way out:I find it useful when including or requiring:
dbconnection.php, _functions.php in files that are actually processed,
rather than including on header. Which is included itself.
So if your header and footer is included, simply include all your functional files before header is included.
For those who are scratching their hairs to find out why in earth this little function should cause a memory leak, sometimes by a little mistake, a function starts recursively call itself for ever.
For example a Proxy Class that has the same name for a function of the object that is going to proxy it.
Sometimes you may forget to bring that little actualObjec member and because the Proxy actually has that doSomething method, PHP would't give you any error and for a large class, it could be hidden from the eyes for a couple of minutes to find out why it is leaking the memory.
Running the script like this (cron case for example):
php5 /pathToScript/info.php
produces the same error.The correct way:
php5 -cli /pathToScript/info.php
It's very easy to get memory leaks in a PHP script - especially if you use abstraction, such as an ORM. Try using Xdebug to profile your script and find out where all that memory went.