I can tell you one problem right away. This part won't work with pipe streams like php files:
//get the length of file in bytes
fseek(file, 0, SEEK_END);
byte_length = ftell(file);
fseek(file, 0, SEEK_SET);
To get the load() function working correctly 100% of the time, one usually needs to read from the stream progressively and use realloc() when needed.
DinoCoderSaurus gave some advice about it here: pset6 (webserver) - hello.php not loading properly