Page 1 of 1
[SOLVED] Multiple include calls
Posted: Thu Aug 16, 2007 9:27 am
by Defkon1
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
Re: Multiple include calls
Posted: Thu Aug 16, 2007 9:40 am
by superdezign
Defkon1 wrote:at the moment it needs about 20-30sec only for include all those classes... how can i speed up the process?
I doubt the problem is in the inclusion if they are just classes. Try timing it.
Code: Select all
$startTime = microtime();
include "path/to/file.php";
echo "Time to include file.php: " . (microtime() - $start);
Posted: Thu Aug 16, 2007 10:11 am
by Defkon1
thanks for your reply.
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
?>
and the output is:
Code: Select all
Start: 17:05:03
start engine: 0.030983
classes: -0.051248
End: 17:06:04
about 1 minute...

Posted: Thu Aug 16, 2007 12:21 pm
by Christopher
How big are the small classes and one big class? What are the specs of the server? Why is your classes directory in the root directory?
Posted: Thu Aug 16, 2007 12:23 pm
by miro_igov
Add echo "Class #1: ".(microtime()-$startEngine)."\n"; after each include and you will see what makes it loading slow.
Posted: Thu Aug 16, 2007 4:39 pm
by AKA Panama Jack
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.
Posted: Fri Aug 17, 2007 4:28 am
by Defkon1
@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)
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:26
@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...

Posted: Fri Aug 17, 2007 5:16 am
by Defkon1
Posted: Fri Aug 17, 2007 5:22 am
by Chris Corbyn
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.
Posted: Fri Aug 17, 2007 6:36 am
by Defkon1
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.
thanks for this extra useful info!
