'What is While Feof alternative for big file downloads?

I use this while loop to fetch the file;

<?php 
while(!feof($fp)){ //get this file with feof but dont tell file location on the server 
$buffer =  fread($fp,$sizechunk);
echo $buffer; 
ob_flush();
flush();
}

But feof is not good for large downloads. Because I'm serving large files and the download must be complete before it can exit the while loop. Exit it from the loop is very simple, but I need to exit the loop and the download will continue. Or I need to pull it with another code. Any idea?

Since the file stays in the loop, PHP seems to be used continuously and if I can't remove it, PHP will crash after the number of downloads is 6+.

I tried the following server-side changes;

In PHP settings:

max_execution_time = 60 to 3600

max_input_time = 30 to 7200

max_input_vars = 30 to 7200

post_max_size = 200M to 200000M

memory_limit = 2000M to 30000M

sub process = 20 to 200


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source