PHP Classes

memory problems

Recommend this page to a friend!

      Split and merge files  >  All threads  >  memory problems  >  (Un) Subscribe thread alerts  
Subject:memory problems
Summary:Allowed memory size exhausted on large files
Author:e aposztrof
Date:2013-07-10 01:20:19
Update:2014-02-16 12:37:21

  1. memory problems   Reply   Report abuse  
e aposztrof - 2013-07-10 01:20:19
This is a great class, but please help me to solve the memory allocation problem. In example:
When i have a 16815544 bytes large file, and
ini_set('memory_limit', '8M');
applied, the result is:
Allowed memory size of 8388608 bytes exhausted (tried to allocate 7415129 bytes) in / on line 40

  2. Re: memory problems   Reply   Report abuse  
Arash Hemmat - 2014-02-16 12:37:21 - In reply to message 1 from e aposztrof
Sorry i couldn't answer sooner, this class puts the file content in memory in spliting and mergin process so it won't be able to handle big files with a limited memory. The only solution is to increase the memory allocated to php. I can't think of any other solution for handling big files.

  3. Re: memory problems   Reply   Report abuse  
Mck - 2015-02-02 17:00:26 - In reply to message 2 from Arash Hemmat
the merge method could be rewritten to

- This function merges splited files that are splited with above -
- split_file function. -
function merge_file($merged_file_name,$parts_num)
//put splited files content into content
$mhandle=fopen($merged_file_name, 'wb') or die("error creating/opening merged file");
$file_size = filesize('splited_'.$i);
$handle = fopen('splited_'.$i, 'rb') or die("error opening file");
$content = fread($handle, $file_size) or die("error reading file");
//write content to merged file
fwrite($mhandle, $content) or die("error writing to merged file");
return 'OK';
}//end of function merge_file