0

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

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. 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

Govind Samrow
  • 9,981
  • 13
  • 53
  • 90
rugbert
  • 11,603
  • 9
  • 39
  • 68

1 Answers1

1

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. 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. Open input file for reading, and output file for writing, so the data won't get corrupted.

Community
  • 1
  • 1
Mikhail Zhuravlev
  • 969
  • 2
  • 10
  • 22
  • So when reading the file line by line (in the same script) memory use is decreased? So memory is only allocated while running the regex on a per line basis and does not accumulate for the entire script? – rugbert Aug 24 '16 at 11:13
  • Yes, when file of any size is opened only small amount of memory is allocated for the handle resource. When you read a line, that data is stored in a variable. – Mikhail Zhuravlev Aug 24 '16 at 11:35
  • Ih that's awesome. Ok then, I'll just take that regex and try running it against the dump on a line per line basis. – rugbert Aug 24 '16 at 11:36
  • 1
    Take a note: this very approach can be only taken if each line can be processed by itself, in case if processing needs some wider context, more complex means should be applied. – Mikhail Zhuravlev Aug 24 '16 at 11:38
  • This is perfect, I rewrote the script to run the regex on a line by line basis and it works. thanks! – rugbert Aug 25 '16 at 14:40