Processing large (over 1 gigabyte) files in PHP using stream_filter_ *

$fp_src=fopen('file','r');

$filter = stream_filter_prepend($fp_src, 'convert.iconv.ISO-8859-1/UTF-8');

while(fread($fp_src,4096)){
    ++$count;
    if($count%1000==0) print ftell($fp_src)."\n";
} 

When I run this, the script ends up consuming ~ 200 MB of RAM after going through just 35 MB of the file.

Running without firmware stream_filter with a constant memory area of ​​~ 10 MB.

What gives?

+3
source share
3 answers

You only need to register custom filters. iconv. This is not a specific operation using the flow filter for rot13, demonstrates this behavior.

+1
source

From what I'm reading here , you are not doing it right stream_filter_prepend(), although there may be something that I misunderstand about the process.

Als, , , , iconv - , .

.

0

Any specific reason you want to use stream_filter_prepend ()? If this causes memory problems, I will find another way to do what it does.

0
source

Source: https://habr.com/ru/post/1698775/


All Articles