Hello,
I use the following function to get data out of a file (myfile.dat) and write it to a second file (myfile1.dat):
$fs=fopen("myfile.dat","r");
$fd=fopen("myfile1.dat","w");
$buffersize=4096;
$buffer = fread($fs,$buffer_size);
while (!feof($fs))
{
fwrite($fd,$buffer);
$buffer = fread($fs,$buffer_size); //Problem HERE
}
fclose($fs);
fclose($fd);
But when I run it on a PHP machine with the standart memory value (8M😎 I get this error message, when I try to transfer big files:
"Allowed memory size of 8388608 bytes exhausted (tried to allocate 8192 bytes)" (Problem HERE).
Why is this function using so much memory?
I think that it works like this:
read file packet - write file packet to 2nd file and so on...
So theoretically it should only need something about $buffersize !
Or does the fread/fwrite function also buffer the whole file in the memory?
thanks,
harry