Page 1 of 1
PHP scalability, efficiency
Posted: Sun Jun 23, 2002 11:09 am
by 9902468
Are there programs that can be used to measure script execution times etc.? I'm writing rather massive scripts, and I'm about at 1200 lines of include code per page, (That every page uses...) + plus the actuall content. I'm thinking if I should move all sql code to a inc. file and make functions out of sql events as Matt Zandstra suggests in PHP Trainer kit. (Like add_new_user() etc.) Code would undoubtly be easier to port to work with other databases etc.
The real question is that if I include a file that has 2500 lines of code, (of witch about 50 - 100 will be executed) how much is this going to slow down a page request compared scenario where the 40 -75 lines are hard - coded to a content file? I know that PHP does atleast syntax checking to whole include file prior to executing wanted parts.
I believe that this (performance) isn't something to worry about, but thought that I should check what you pros think... (Don't have to worry yet, production version is the one that has to work fast enough...

)
Posted: Sun Jun 23, 2002 2:11 pm
by will
i'm not sure what others use, as most of my apps are small enought that it wouldn't matter too much either way... but here is a way to test page load time....(keep in mind, this is the time it takes for the PHP to be executed, it has nothing to do with the time it takes to send the page from the server to your browser)...
Code: Select all
//define this function somewhere
function getMicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
//add this to the top of your page, or at the top of the first included file, like a header.inc or something
$time_st = getMicrotime();
//add this to the bottom of your page
$load_time = getMicrotime() - $time_st;
echo 'Page served up in '.$load_time.' seconds;
microtime will allow you to measure fractions of a second, where has something like date() only grabs whole seconds.
Posted: Sun Jun 23, 2002 10:52 pm
by jason
Okay, several things you need to consider:
Realistic outlook of need speed. How much load do you really expect to put on the code? I know a lot of my work I don't worry so much about server load because it's backend admin area and reporting stuff. Only a handful of people are going to use it, and not at the same time. Besides, they aren't customers, but the marketing department and what not.
Secondly, do you really need to put all database functions into one file? For PHPCompelete, I have functions.devblogs.php, which is all the functions (non-display) that deal with devBlogs, and I will use 90% of the code in their each time. Rather than create your files for the action the functions will be taking (contacting the database), create your files for the purpose of the functions (managing user data, for example). This way, when you include a file, you are using most of the code.
Thirdly: No, 2500 LOC won't cause a problem. I work in a pretty big system, (think hundreds of thousands of LOC) and it doesn't get bogged down, and we include just at the start a lot more than 2500 lines.
Next, if speed is really that much of a concern, consider using APC, or Zend Cache, or the like, to speed up the processing of the code. Or even consider rewriting some of the code in C, which will always be faster than PHP. If a few functions are the bottleneck (honestly, rarely the case), you can rewrite them in C and make it a PHP extension.
But no, I don't think you have to worry.
Posted: Sun Jun 23, 2002 11:45 pm
by 9902468
Thanks for your thoughts. Jason pointed out few things that I should really have noticed myself, but as I suspected I don't have to worry at all about performance... System is used in intranet so net speed isn't the problem, but I have read that an application should have response time of 1 second or less in order to appear to the user as an realtime application. (Anymore beyond that and users are starting to get "bored", or as some say, less productive.) So, I'm not doing anything that heavy, I'm just interested what the response time will be. (And Will gave me a solution to monitor that, or script execution atleast.) This might sound like useless time wasting, but after I red this book about ui's it seemed like something to consider.
Posted: Mon Jun 24, 2002 5:45 am
by 9902468
Ok php has some power, after short testing I'm at about 0,32 secs per page when loading all excluding content. Thats way faster than I thought, somehow i presumed that php is slooooooowwww. (Ok I'm not loading all, cause that ldap thingy keeps givin' me trouble)
thx again
Posted: Mon Jun 24, 2002 7:31 am
by epsilon
Maybe you could use Gzip to make it faster
ob_start("ob_gzhandler");