[SOLVED] Multiple include calls
Moderator: General Moderators
[SOLVED] Multiple include calls
hello everybody
i have a function that needs 5 small classes and 1 big class to execute properly: so i've inserted that files for inclusion in the code of the function.
at the moment it needs about 20-30sec only for include all those classes... how can i speed up the process?
thanks in advance
i have a function that needs 5 small classes and 1 big class to execute properly: so i've inserted that files for inclusion in the code of the function.
at the moment it needs about 20-30sec only for include all those classes... how can i speed up the process?
thanks in advance
Last edited by Defkon1 on Fri Aug 17, 2007 5:18 am, edited 1 time in total.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Multiple include calls
I doubt the problem is in the inclusion if they are just classes. Try timing it.Defkon1 wrote:at the moment it needs about 20-30sec only for include all those classes... how can i speed up the process?
Code: Select all
$startTime = microtime();
include "path/to/file.php";
echo "Time to include file.php: " . (microtime() - $start);thanks for your reply.
this is my test script:
and the output is:
about 1 minute... 
this is my test script:
Code: Select all
<?php
echo "Start: ".date("H:i:s", time())."\n"; //start time
//timing start env
$startEngine = microtime();
include('startengine.php')
$echo "start engine: ".(microtime()-$startEngine)."\n";
//timing classes inclusions;
$startTime = microtime();
include ('/class/classe1.php');
include ('/class/classe2.php');
include ('/class/classe3.php');
include ('/class/classe4.php');
include ('/class/classe5.php');
include ('/class/classe6.php');
echo "classes: ".(microtime()-$startEngine)."\n";
echo "End: ".date("H:i:s", time())."\n"; //endtime
?>Code: Select all
Start: 17:05:03
start engine: 0.030983
classes: -0.051248
End: 17:06:04- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Large classes in PHP is usually a bad thing because they can take a LONG time to create the object. This is because every time an object is created the code is re-parsed and memory is allocated for the new object. PHP is not fast at doing this with large classes.
I would venture to bet that each of those classes you are loading has code that is being executed immediately upon loading. This would explain why you are seeing large execution times. Including files, no matter how large, is extremely FAST but if there is code that is executed after the file is included that will give the APPEARANCE the include is show when in fact it is the included file executing that is low.
I would venture to bet that each of those classes you are loading has code that is being executed immediately upon loading. This would explain why you are seeing large execution times. Including files, no matter how large, is extremely FAST but if there is code that is executed after the file is included that will give the APPEARANCE the include is show when in fact it is the included file executing that is low.
@arborint
small classes are about 20-30 lines, with a couple of properties and relative setter/getter methods
the big one is about 700 lines, with several methods...
@miro_igov
single classes timing (the big one is the last one)
@AKA Panama Jack
in this test script i've just included those classes, without using them, without instantiating any object from them...
thank you all for your replies...
small classes are about 20-30 lines, with a couple of properties and relative setter/getter methods
the big one is about 700 lines, with several methods...
@miro_igov
single classes timing (the big one is the last one)
Code: Select all
Start: 11:20:25
start engine: 0.090657
class1: 0.10196
class2: 0.117399
class3: -0.745825
class4: 0.106746
class5: 0.039889
class6: 0.087155
End: 11:21:26in this test script i've just included those classes, without using them, without instantiating any object from them...
thank you all for your replies...
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
By the way, you might want to have a look at what microtime() is returning
It returns a string with a space in the middle so doing maths on it won't work 
In PHP 5.1+ you can call microtime(true) to get a floating point number, but in older versions you need to explode() the string, add the chunks then (float) cast the result. You can see you even got a negative value back in your logic and your figures will be way out.
In PHP 5.1+ you can call microtime(true) to get a floating point number, but in older versions you need to explode() the string, add the chunks then (float) cast the result. You can see you even got a negative value back in your logic and your figures will be way out.
thanks for this extra useful info!d11wtq wrote: In PHP 5.1+ you can call microtime(true) to get a floating point number, but in older versions you need to explode() the string, add the chunks then (float) cast the result. You can see you even got a negative value back in your logic and your figures will be way out.