简体   繁体   English

PHP CLI内存不足

[英]PHP CLI running out of memory

I'm trying to reserialize a 1gb sql dump using the fix-serialization.php file from https://github.com/Blogestudio/Fix-Serialization/blob/master/fix-serialization.php 我正在尝试使用https://github.com/Blogestudio/Fix-Serialization/blob/master/fix-serialization.php中的fix-serialization.php文件重新序列化1gb sql转储

with this command: 使用此命令:

php -d memory_limit=-1 fix-serialization.php dump.sql 

But I get the following error 但我收到以下错误

PHP Fatal error:  Out of memory (allocated 2328100864) (tried to allocate 18446744071742389167 bytes) 

I get the same error with when I try: 我尝试时遇到相同的错误:

php -d memory_limit=2000M fix-serialization.php dump.sql 

Obviously my computer does not have 18446744071 GB of ram. 显然我的电脑没有18446744071 GB的RAM。 I'm getting this error on both a MBP and my Ubuntu machine and I've tried running this script on php5.6 and 7 我在MBP和我的Ubuntu计算机上都收到此错误,并且尝试在php5.6和7上运行此脚本

Looks like you shoud make your own solution. 看起来您应该自己制定解决方案。 This script won't fit since it reads the whole file at once and then passes the whole file to the preg_replace . 该脚本不合适,因为它会立即读取整个文件,然后将整个文件传递给preg_replace That regex is quite complex, so it needs a lot of memory for processing such big strings. 该正则表达式非常复杂,因此它需要大量内存来处理如此大的字符串。 You should read one data line , then proccess that line and write it to the output file. 你应该读一个数据线 ,然后proccess该行并将其写入到输出文件。 Open input file for reading, and output file for writing, so the data won't get corrupted. 打开输入文件进行读取,并打开输出文件进行写入,因此数据不会损坏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM