I'm not used to PHP but I think somewhere in 'read_file_guts.php' causes OOM. How about using stream to read file contents?
https://www.php.net/manual/en/function.file-get-contents.php
https://www.php.net/manual/en/function.stream-get-contents.php
In this way you can read big file by small chunks rather than whole into the memory I think.