Hello. I was faced with the task of giving the user files from a third-party server, but the memory on the VDS is not infinite and downloading the entire file is not an option. fopen supports url, but how to send the file through the descriptor and not load it into memory?

PS Do I understand correctly that if you output everything to echo, then the data will be dropped into the output stream bypassing the memory?

    1 answer 1

    // читаем файл и отправляем его пользователю if ($fd = fopen($file, 'rb')) { while (!feof($fd)) { print fread($fd, 1024); } fclose($fd); } 

    As for the data reset, the question is not quite clear. They will not be stored in memory during the entire execution of the script. If this was meant, then yes, the data will be reset. But in general read here

    • Thank you for what you need! At the expense of the reset, I said that when using print, the data is saved to the internal buffer or is it immediately sent to the user? - Andrey Frimuchkov