Does opening and closing php tags multiple times increases page load? [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-12 10:51:46

问题


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 :)

  1. Does opening and closing php tags ( <? php code ?>) multiple times increases page load time?

  2. How about using include templatepath multiple times?

Thank you


回答1:


  1. Theoretically yes, but the difference is so miniscule that in almost all cases it wouldn't matter.

  2. 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!




回答2:


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.



来源:https://stackoverflow.com/questions/11853130/does-opening-and-closing-php-tags-multiple-times-increases-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!