On Friday 20 July 2007, Sascha Braun, CEO @ ejackup.com wrote:
> Dear People,

> The webserver does only contain the webspace filesystem structure as
> well as 5 line of PHP Code dummies, for every document in the content
> management system, to avoid the usage of mod_rewrite.

I inherited a CMS at work that did that.

Stop.  Now.  Use mod_rewrite.  You'll live longer and spend less on 
hair-regrowth medication.

mod_rewrite is not itself a huge performance hit.  If you're on a dedicated 
server then you can move the mod_rewrite directive to the apache.conf file 
and disable .htaccess files, which can give you a performance boost, but if a 
reasonably simple mod_rewrite is the difference that is killing your server 
then you need to rethink your server.  It's a minor issue.  You'll get a 
better performance gain out of a slightly faster processor.

Your PHP coding style itself likely has little if any impact on performance.  
pre vs. post increment is going to be a tiny fraction of a percent compared 
to the time taken to parse code, hit the database, hit the disk, etc.  

As others have said, benchmark benchmark benchmark.  As a general guideline, 
the big performance killers I've run in to include:

- Parsing.  Opcode cache is good, but if you can give it less to cache that 
helps, too.  You said you're already using autoload(), which helps, but make 
sure that you're not loading gobs of code that you don't use.  Even with an 
opcode cache, that will eat up RAM.

- SQL in loops.  Never do this.  

- Cache pretty much everything that you get back from the database if you can, 
using a static variable.  (Not a global; a static variable local to a 
function or method, or a private class variable.)  If you're loading complex 
objects, cache the fully prepared version.  That not only provides a 
performance boost, but also provides you with a good 
single-point-of-optimization because it's then much easier to shift that from 
a static variable or static array to a memcached storage.  

- Limit your individual transfers.  Oft-forgotten, but remember that every 
file the browser has to request is another HTTP hit on the server.  Even if 
the response from the server is "nope, no change", it's still an HTTP hit.  
That can really hurt your effective performance, both on the server side and 
client side.  Merge your CSS and JS into as few files as reasonable, even if 
that means that you send more than you need to on the first page request.  It 
helps overall.  You can do that manually or automatically.  (Drupal, for 
instance, auto-aggregates CSS and in the next version will auto-aggregate JS, 
too.  That's been a big performance boost.)  The same goes for image files.

- Apropos of the last, Firebug!  The latest version has a great profiler that 
can show you how long each HTTP request takes.  You may find that you spend 
most of your browser-load time on things that don't involve PHP at all.

- EXPLAIN your SQL.  That is, the MySQL EXPLAIN command prefixed to any SELECT 
query will tell you how MySQL is going to parse and process it.  Odds are 
good that adding a few well-placed keys/indexes will make your SQL an order 
of magnitude faster or more.  Also, watch out for filesort.  Any time a query 
has to do a filesort, it gets slow.  It always has to filesort if you are 
doing a WHERE and ORDER BY that use fields in different tables.  Avoid that 
if you can.  Much more information in a MySQL group. :-)

Again, benchmark it from every direction you can.  Odds are, though, that your 
PHP code itself is not the bottleneck but the server configuration, SQL 
server, HTTP traffic, etc. are where you're really dying.

Cheers.

-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to