When you include or require a file in PHP, such as with the following, how much is actually transferred from the server?
index.php - 20kb, 10kb of which is HTML that would be a 10kb file if in its own HTML file. ./include/file.php - 30kb. Inside of file.php is HTML that would be 20kb's worth of data if it was inside its own HTML file.
.javascript.js - 15kb
If index looks like this:
<?PHP
....
// 10Kbs worth of stuff
// links the JS file via <script> in the header
require( './include/file.php' );
?>
How many bytes does the server transfer? I think the answer is that the server reads the PHP, so it accesses all 50kb's (not the 15 for the JS), but it uploads and transfers the 10kb of HTML inside of the index file, the 20kb's of HTML inside the included/file.php, and the JS at 15kb's, totalling 45kb's transferred.
Can someone confirm or show me the errors of my way?
Require just includes a file. Nothing else.
require( './include/file.php' );
You are including code in the current file that resides in ./include/file.php
. After that the resultant file will run. And the output of this file will be send to browser.require
you pass a path to a file. This path can be remote(if you enable in php.ini
) or local (as in example). If its a remote file, it'll be downloaded to your server first for sure. But that doesn't mean it'll be downloaded to your client.I'm not sure you understand what require()
is doing. It just causes PHP to include the specified file locally* -- nothing "over the internet" is involved.
*: I'm intentionally ignoring remote includes here, because they're an abomination, and are disabled by default.