How can PHP efficiently read and parse a text file generated by a Unix command like "df > File.txt" to extract specific information of interest?

To efficiently read and parse a text file generated by a Unix command like "df > File.txt" in PHP, you can use file handling functions to read the contents of the file line by line. Then, you can use regular expressions or string manipulation functions to extract the specific information of interest, such as disk usage statistics. Finally, you can process and display this extracted information as needed.

<?php
$file = fopen("File.txt", "r") or die("Unable to open file!");
while(!feof($file)) {
    $line = fgets($file);
    // Perform parsing or extraction logic here
    if (strpos($line, "/dev/sda1") !== false) {
        $parts = preg_split('/\s+/', $line);
        $total_space = $parts[1];
        $used_space = $parts[2];
        $available_space = $parts[3];
        echo "Total Space: $total_space, Used Space: $used_space, Available Space: $available_space\n";
    }
}
fclose($file);
?>