Re: Structured Code vs. Performance
| From: | Jochem Maas | Date: | Thu, 29 Nov 2007 08:43:08 +0000 |
| Subject: | Re: Structured Code vs. Performance | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265204@lists.php.net to get a copy of this message | ||
Tomi Kaistila wrote:
...
>
> You can avoid duplication by only using require_once or include_once. PHP
indeed require_once() and include_once() help with maintainability but it
should be mentioned that if you are going to use an op-code cache (as Rob
Cummings mentioned also) then it is highly recommended that you stick to
using require() and include() as, IIRC, op-code caches handle your includes
much faster when they are 'unconditional' (probably not the correct word in this
context but what I mean is that there is no check to see if the file has been
previously included)
also using an absolute path in your include statements helps php (and the
op-code cache if you use it) it go a little faster because there is no need
to work through the directories defined in the include_path ini setting to
find the file.
> automatically does the checking that the file is not included if it has
> already been included once. The Zend framework works this way for instance.
> Just simply require_once, at the beginning of the file, everything the file
> in question needs.
>
> Constants on the global scope are a bit of a different case. But if you do a
> lot of objects, you can instead of the global scope put all of your
> constants into classes, which works just as well. This avoids name
> conflicts.
>
> Hope that answered your question.
>
>
> Tomi Kaistila
> PHP Developer
>