Possible Duplicate:
Opening/closing tags & performance?
This is a newbie question, but I could not find a clear answer on the net, so please don't laugh :)
Does opening and closing php tags ( <? php code ?>
) multiple times increases page load time?
How about using include templatepath multiple times?
Thank you
It is recommended that a closing PHP tag shall be omitted in a file containing only PHP code so that occurrences of accidental whitespace or new lines being added after the PHP closing tag, which may start output buffering causing uncalled for effects can be avoided.
For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response. The Yii framework also uses this style.
There are four different pairs of opening and closing tags which can be used in PHP.
If a file contains only PHP code, it is preferable to omit the PHP closing tag at the end of the file.
Does opening and closing php tags (
<? php code ?>
) multiple times increases page load time?
NO - I'm answering even though you've accepted, because everyone deserves to know what actually happens.
When PHP parses a file it tokenises everything outside of the tags as T_INLINE_HTML.
This is turned directly into a ZEND_ECHO
Closing and re-opening a tag is exactly the same speed as if you were echoing the html from within a single <?php ?>
block.
How about using include templatepath multiple times?
Yes the more files you include, the longer it will take to load a page, especially if they have to be read from disk each time and you are not utilising various caching mechanisms.
Theoretically yes, but the difference is so miniscule that in almost all cases it wouldn't matter.
Not sure about what you mean. If there is a possibility of a file being included multiple times, use include_once
or require_once
. This will prevent multiple loads and prevents errors like 'Cannot redeclare class'. Again this is more expensive than include
and require
, but more stable.
As a side note, your questions are not anything related to code, and I am sure these have already been asked and answered multiple times in SO, so please try to search/ask better next time :)
All the best!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With