Reading by large file line in php

When a large file in php is read as file_get_contents, it is loaded into memory at once, and a situation in which php script cannot be executed due to insufficient memory occurs.
At this time, if you read line by line, you can avoid running out of memory.

Below is an example code
$handle = fopen("inputfile.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        // process the line read.
    }

    fclose($handle);
} else {
    // error opening the file.
} 

Comments

Popular posts from this blog

Enabling Com Port on Hyper-V 2nd Generation VM / Windbg

DLL Injection using CreateRemoteThread in Windows 10

Using Overlapped I / O in DeviceIoControl