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

Posted by mike on Stack Overflow See other posts from Stack Overflow or by mike
Published on 2008-10-27T22:58:50Z Indexed on 2010/03/14 20:05 UTC
Read the original article Hit count: 129

Filed under:
|
|
$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 35MB of the file.

Running it without the stream_filter zips right through with a constant memory footprint of ~10 MB.

What gives?

© Stack Overflow or respective owner

Related posts about php

Related posts about streams