I have to read a very large text file with PHP (about 1 million lines and 45.4 MB) and speed is critical. The file is layed out like so.
Notice the extra space before and after each line
Code:
{"one":1727294,"two":2667541,"three":9998168}
{"one":7005310,"two":9377441,"three":4658508}
{"one":2638549,"two":7931823,"three":992431}
{"one":8817443,"two":1587524,"three":6495056}
{"one":5009765,"two":4831848,"three":2782592}
{"one":9882507,"two":4866943,"three":7389221}
{"one":7161254,"two":281677,"three":9001464}
{"one":6177062,"two":661010,"three":4880065}
{"one":850830,"two":5882873,"three":4219360}
{"one":5865173,"two":8852539,"three":6194152}
Obviously, the file is too large to just load the entire thing into PHP so I'm using
fscanf to read the file line by line.
Right now I have it so I can select an entire line if I know the whole thing. Here is what I got for that:
PHP Code:
while($data = fscanf($fh,"\n{\"one\":1054687,\"two\":8728332,\"three\":2499389}%s\n"))
{
print_r($data);
}
What I want to do is be able to select one entire line with only knowing part of it (ex: "three":4219360). I'm not sure how to go about doing this because I have very little experience with fscanf and function of the like. I've tried something like this but it returns all of the rows:
PHP Code:
while($data = fscanf($fh,"\n%s\"three\":2499389%s\n"))
{
print_r($data);
}
I do NOT want to have to load every line into PHP and check it that way as that could be very slow.