且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

fputcsv不适用于大型阵列

更新时间:2022-06-23 00:40:39

PHP将此类变量加载到内存中.根据您的php.ini设置,每个脚本都有允许使用的最大内存量.

PHP loads variables like these into memory. And every script has a maximum amount of memory it is allowed to use, based on your php.ini settings.

此外,复制变量时,它们可能占用内存的两倍.源内存和目标内存.我不确定fputcsv的内部结构,但有可能将整个数组在内部转换为csv对象",然后写出到文件中.

Also, when variables are copied, they can take up double the space in memory. The source memory, and the destination memory. I'm not sure the internals of fputcsv, but it's possible that the entire array is being converted to a csv "object" internally, then written out to file.

因此,请记住,每次复制时,您的内存使用量都可能翻倍.

So, remember that you're possibly doubling your memory usage any time you copy.

至少,请在php.ini中检查"memory_limit".如果您需要特别针对一个脚本增加它,则可以使用以下命令在您的脚本中进行设置:

In the very least, check your "memory_limit" in your php.ini. If you need to increase it for one script in particular, then you can set it in your script with:

ini_set('memory_limit','16M');