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 04:10

I had the error below while running on a dataset smaller than had worked previously.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in C:\\workspace\image_management.php on line 173

As the search for the fault brought me here I thought I'd mention that it's not always the technical solutions above but something more simple. In my case it was Firefox. Before I ran the program it was already using 1,157M.
Turns out that I'd been watching a 50 minute video a bit at a time over a period of days and that messed things up. It's the sort of fix that experts correct without even thinking about it, but for the likes of me it's worth baring in mind.

查看更多
时光乱了年华
3楼-- · 2018-12-31 04:11

You can properly fix this by changing memory_limit on fastcgi/fpm

$vim /etc/php5/fpm/php.ini

Change memory like from 128 to 512 see below

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M

to

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 512M
查看更多
牵手、夕阳
4楼-- · 2018-12-31 04:11

Change the memory limit from php.ini file and restart apache. After restart run the phpinfo(); function from any php file for memory_limit change confirmation.

memory_limit = -1

memory limit -1 means there is no memory limit set it's now maximum.

查看更多
像晚风撩人
5楼-- · 2018-12-31 04:12

Changing the memory_limit by ini_set('memory_limit', '-1'); is not a proper solution. Please don't do that.

Your PHP code may have a memory leak somewhere and you are telling the server to just use all the memory that it wants. You wouldn't have fixed the problem at all. If you monitor your server, you will see that it is now probably using up most of the RAM and even swapping to disk.

You should probably try to track down the offending code in your code and fix it.

查看更多
后来的你喜欢了谁
6楼-- · 2018-12-31 04:12

After enable these two lines.
It's started working

; Determines the size of the realpath cache to be used by PHP. This value should
; be increased on systems where PHP opens many files to reflect the quantity of
; the file operations performed.
; http://php.net/realpath-cache-size
realpath_cache_size = 16k

; Duration of time, in seconds for which to cache realpath information for a given
; file or directory. For systems with rarely changing files, consider increasing this
; value.
; http://php.net/realpath-cache-ttl
realpath_cache_ttl = 120

查看更多
登录 后发表回答