I’ve created a small MVC framework in PHP. Pages are created dynamically, and are then returned to the client/browser.
At this moment I create the entire file (HTML output) in the variable $content.
Next, I write this content in a temporary file, and require this file, thus returning the content to the client.
Now, I was wondering… Can’t I just send it from memory, i.e. just echo-ing the variable:
<?php
...
echo $content;
...
?>
Is this effectively the same as writing it to a temp file and then requiring/including it, only faster? Or do you have any better tips?
Yes, you can absolutely just echo it out.
The value in storing them in temporary files would be for instances where you an just require that same temp file instead of doing all of your heavy lifting all over again (logic, db calls, etc)