我有一堆客户端销售点(POS)系统,这些系统定期将新的销售数据发送到一个集中的数据库,该数据库将数据存储到一个大数据库中,以便生成报告。

客户机POS基于PHPPOS,我实现了一个模块,该模块使用标准XML-RPC库将销售数据发送到服务。服务器系统构建在CodeIgniter上,并为webservice组件使用XML-RPC和XML-RPC库。每当我发送大量的销售数据(从销售表中只有50行,从sales_items中单独的行用于销售中的每个项目),我得到以下错误:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 54 bytes)

128M是php.ini中的默认值,但我认为这是一个巨大的数字。事实上,我甚至尝试过将这个值设置为1024M,它所做的只是花费更长的时间来出错。

至于我所采取的步骤,我已经尝试在服务器端禁用所有处理,并对其进行了修改,使其返回一个罐装响应,而不管输入是什么。但是,我认为问题出在数据的实际发送上。我甚至尝试过禁用PHP的最大脚本执行时间,但它仍然出错。


当前回答

像这样运行脚本(以cron为例):php5 /pathToScript/info.php会产生同样的错误。

正确的方法:php5 -cli /pathToScript/info.php

其他回答

启用这两行后,它开始工作:

; 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

你可以通过修改fastcgi/fpm的memory_limit来解决这个问题:

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

更改内存,例如从128更改为512,如下所示

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

to

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

对于Drupal用户,以下是Chris Lane的回答:

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

可以,但我们得把它放在开幕式之后

<?php

标记在站点根目录的index.php文件中。

像这样运行脚本(以cron为例):php5 /pathToScript/info.php会产生同样的错误。

正确的方法:php5 -cli /pathToScript/info.php

我发现当在实际处理的文件中包含或要求_dbconnection.php_和_functions.php时,而不是在头文件中包含时,它很有用。这是包含在自身中的。

因此,如果包含了页眉和页脚,只需在包含页眉之前包含所有函数文件。