Fatal Error: Allowed Memory Size of 134217728 Byte

2018-12-31 03:13发布

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.

23条回答
人气声优
2楼-- · 2018-12-31 03:50

The memory allocation for PHP can be adjusted permanently, or temporarily.

Permanently

You can permanently change the PHP memory allocation two ways.

If you have access to your php.ini file, you can edit the value for memory_limit to your desire value.

If you do not have access to your php.ini file (and your webhost allows it), you can override the memory allocation through your .htaccess file. Add php_value memory_limit 128M (or whatever your desired allocation is).

Temporary

You can adjust the memory allocation on the fly from within a PHP file. You simply have the code ini_set('memory_limit', '128M'); (or whatever your desired allocation is). You can remove the memory limit (although machine or instance limits may still apply) by setting the value to "-1".

查看更多
公子世无双
3楼-- · 2018-12-31 03:50

not sure if this answer will be of any help, but when I removed the following lines from my code all worked OK!

set_include_path(get_include_path() . get_include_path().'/phpseclib');

include_once('Net/SSH2.php'); include_once('Net/SFTP.php');

These lines were included in every file am running, when running the files one by one all worked OK, but when running all files together I got the memory leak issue. Somehow the "include_once" is not including things once, or am doing something wrong..

查看更多
浅入江南
4楼-- · 2018-12-31 03:53

I kept getting this error, even with memory_limit set in php.ini, and the value reading out correctly with phpinfo().

By changing it from this:

memory_limit=4G

To this:

memory_limit=4096M

This rectified the problem in PHP 7.

查看更多
临风纵饮
5楼-- · 2018-12-31 03:56

ini_set('memory_limit', '-1'); overrides the default PHP memory limit.

查看更多
明月照影归
6楼-- · 2018-12-31 03:56

If you're running a WHM-powered VPS (Virtual Private Server) you may find that you do not have permissions to edit PHP.INI directly; the system must do it. In the WHM host control panel, go to Service Configuration > PHP Configuration Editor, modify memory_limit:

Updating memory_limit on WHM 11.48.4

查看更多
琉璃瓶的回忆
7楼-- · 2018-12-31 03:57

For Drupal users, this Chris Lane's answer of:

ini_set('memory_limit', '-1');

works but we need to put it just after the opening

<?php

tag in the index.php file in your site's root directory.

查看更多
登录 后发表回答