0

I am using the following code to create backups of the php variables.

if(file_exists(old_backup.txt))
    unlink('old_backup.txt');
copy('new_backup.txt', 'old_backup.txt');
$content = serialize($some_ar);
file_put_contents('new_backup.txt', $content);

new_backup.txt will have current variables dump and old_backup.txt will have variables dump sometime back in time.

dump size is constant, around 300Mb. But every time above code is run, disk usage increases indefinitely. When the php script killed, disk usage is normal. Not sure where the file handler still open for deleted files. How do I make above code work, without much increase in disk usage.

1 Answers1

1

Not sure about what exactly is causing the disk usage increase, because you posted only a snippet and not the full script. However there are a few things that are not correct for sure:

if(file_exists(old_backup.txt))

should be

if(file_exists('old_backup.txt'))

Then the mere existence of the file does not mean you can unlink it, you should check permissions too. That being said, those aren't good reasons to fill the disk, but we need to see where you get the $some_ar variable from to give better advice.

Lucio Crusca
  • 1,277
  • 3
  • 15
  • 41