Closed Thread Icon

Topic awaiting preservation: PHP Script performance (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=28258" title="Pages that link to Topic awaiting preservation: PHP Script performance (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP Script performance <span class="small">(Page 1 of 1)</span>\

 
H][RO
Paranoid (IV) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-27-2006 02:13

Hey,

Does anyone know if you loose much performance if you have a script with a bunch of functions that never get used. I.e does a script with less functions take up less memory or run faster?


Thanks

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-27-2006 03:46

A script with less functions does run faster.

Remember a PHP page is parsed and compiled everytime the page is accessed this process doesn't care whether the code is used or not.

I can also attest to the fact that this can be an issue with some PHP code frameworks.



.:[ Never resist a perfect moment ]:.

H][RO
Paranoid (IV) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-27-2006 05:31

Okay thanks,

might be worth splitting my base class up a bit into a few classes if thats the case, i think i can structure it a bit better.

H][RO
Paranoid (IV) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-27-2006 05:41

Actually lets say do do require_once on a file with a class and functions. Is that compiled even if you dont create an object of that class?

divinechaos
Bipolar (III) Inmate

From:
Insane since: Dec 2001

posted posted 07-27-2006 05:52

Yes, it's parsed into memory, even if you never instantiate or call anything in that file. Once you include the file (include/require/include_once/require_once) it gets pulled into memory and parsed. So it is a good idea to split up large classes and libraries.

That said, I would imagine there is a point at which the file handling hit outweighs the benefits, breaking things down too much might cause a slowdown too. This might depend on the filesystem and server environment. (This is more an offhand remark, I don't think this point would be easy to reach ... just mean breaking a 2,000 line file into 200 files may not be any better.)

Read this (http://www.whenpenguinsattack.com/2006/07/21/optimizing-object-oriented-php/?2) the other day on PHP optimization and benchmarking. Whether you agree or disagree, there are at least some other things to think about and there are derivative links in the comments.

Cheers,
DC

(Edited by divinechaos on 07-27-2006 05:53)

H][RO
Paranoid (IV) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-27-2006 06:31

Thanks i will have a read


I guess it also needs to be considered if you NEED more performance, currently there are no performance problems and its much easier to maintain then if i split it up at this stage.

At least i know i can optimize it when i get the time to get a boost out of it

divinechaos
Bipolar (III) Inmate

From:
Insane since: Dec 2001

posted posted 07-27-2006 09:09

I considered that maybe something wasn't clear. Including a file only occurs when that code is executed ... so in this (very simple) example:

code:
$x = "a";

if($x == "a") {
  require_once("a.php");
} else {
  require_once("b.php");
}



b.php is never called, even though there is an include statement. So if you break your code up that way, you won't load unnecessary files; it's a better than just having 20 include lines at the top of the file... especially when you deal with a massive app.

Regards,
DC

H][RO
Paranoid (IV) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-27-2006 10:41

Yeh i figured as much, did some testing anyways and most of my scrpipts execute in under 0.05 seconds so its all good for now. The only slow ones are due to ftp operations which seem to be slow by nature.

I think most of loading time is lost with IE anomolies!

« BackwardsOnwards »

Show Forum Drop Down Menu