Re: Includes eating up my time
| From: | Emil Ivanov | Date: | Tue, 31 Jul 2007 11:36:37 +0000 |
| Subject: | Re: Includes eating up my time | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-259885@lists.php.net to get a copy of this message | ||
Consider using the __autoload() function in php.
(also the SPL autoloading features).
It's a way to tell php to load a file when it cannot find a definition for a
CLASS (only for classes).
I don't know how you have set-uped your project, but in mine the only place
in the project where I use include is thie __autoload() function.
In other words - php supports load-on-demand for classes.
Check out http://php.net/__autoload
Regards,
Emil Ivanov
"Dave M G" <martin@autotelic.com> wrote in message
news:46AF0212.9020906@autotelic.com...
> PHP general list,
>
> This is probably obvious to people who are good at PHP, but I'm
>
> I have a PHP based CMS (content management system) built, which has grown
> and become quite robust. It's now spread out over about 30 files, and each
> file represents one class within the object oriented design. Each are a
> couple hundred lines of code, and two or three of the most critical
> classes are over a thousand lines of code.
>
> While first building it, I didn't really anticipate quite that many files.
> What I did is have a file called "includes.php", which list all the files
> to be included. Then I in turn included "includes.php" at the beginning of
> my "index.php" file. Every page request passes through the "index.php"
> file, so that basically means every single file is included at the start
> of every new page request.
>
> I'm using Zend Studio, which has a "profile" option, which shows how long
> it takes for my PHP scripts to complete a request. It has a breakdown
> showing percentages of which scripts are using that processing time.
>
> Currently, my processes are taking under a second, but they can be around
> half a second or more. Although it all happens too fast for me to really
> notice as a person, it seems to me that a half second of processing time
> might be kind of long and lead to scalability problems.
>
> My first question is: Is a half second too long? I'm pretty sure it is,
> but maybe I'm just being paranoid. What do people consider to be
> acceptable time frames for processing a web page similar to what Wikipedia
> delivers?
>
> Most of the time is taken with the includes. Anywhere from 60% to 90% of
> the time it takes to process my scripts is coming from the includes.php
> file.
>
> I read somewhere that it's not a good idea to have more than 10 includes
> in any one place. I'm fine with trying to break up my include requests,
> but I'm unsure as to how. As each function in each class passes around
> objects, it's not clear from looking at the code which ones are used at
> any one time, so I'm unsure how to efficiently include only the necessary
> classes.
>
> My second question is: Is there a systematic way of determining how to
> incrementally include files that people use? Or is it just a constant
> process of testing and checking?
>
> Thank you for any advice.
>
> --
> Dave M G
> Ubuntu Feisty 7.04
> Kernel 2.6.20-16-386