Solved

Highperformance with PHP???

Posted on 2002-07-24
5
218 Views
Last Modified: 2009-12-14
Hi,

I wonder if there are hints and tricks for highperformance-websites programmed in PHP?

Are there points/details which can improve the performance and speed of PHP?

Or is improvement of performance only possible by proper installation and settings of the Webserver and of the Database-Server?
0
Comment
Question by:delphiheaven
5 Comments
 
LVL 40

Accepted Solution

by:
RQuadling earned 25 total points
ID: 7174855
You can compile the PHP using some of the Zend tools. This will stop the interpretation of PHP and simply become execution. Which is faster.

If not, you can use the optimizer (free I think) from Zend. This makes the script a little faster.

Richard.
0
 
LVL 5

Assisted Solution

by:dkjariwala
dkjariwala earned 25 total points
ID: 7177041
As Richard said,
Zend tools can help you.

Also few basic tricks might help you a bit.

Lets say you are using DB for session management and where HEAP tables are used for storing session info. in that case session management becomes really faster.

Make sure that PHP is module under your webserver and not running as CGI binary. This will also help you in having persitent connection with DB. Persitent connection is good idea if you are expecting lot of interaction with DB.

Lot of time ppl use templates which are stored in files. That might cause application to slow a bit. Use smarty which can cache a template too !!

Search Google you can find lots of pointers !!!
JD
0
 
LVL 3

Expert Comment

by:rycamor
ID: 7226880
Yes, there are a few things. My main complaint is PHP programmers who retrieve a whole recordset from a database into PHP, and then go about using PHP array methods to search through the data. This should only be used as a last resort. Do all your data manipulation in SQL. Return only the data you need to show on at that particular point.. no more.

A small point, but if you are echoing (or printing) a string with no variables, use single quotes (so PHP doesn't even look for variables).

There is the compile-time option --enable-inline-optimization, which speeds PHP code.

Zend Optimizer is free, and can speed up complex scripts by approx. 50% (simple scripts cannot really be sped up much anyway). Zend Accelerator costs money, but maintains a compiled cache of your scripts in memory, which is about as fast as it gets.

Choose a good database management system, and choose good database design. This single area is probably the MOST critical point of failure in most PHP websites. (I recommend PostgreSQL, Sybase, Oracle, etc... over MySQL if you have any complexity in your system. MySQL is fine for simple websites, though.)

As JD says, HEAP tables in MySQL provide very fast access, but there are a couple hidden costs in MySQL HEAP tables: 1. No column can be greater than 255 characters, so if you are storing larger values, you must come up with a way of spanning multiple columns or records.
2. MySQL locks HEAP tables upon update, so if you have many sessions being written at the same time to the same table, you will hit a bottleneck fast. (one solution is to create a separate, temporary table for each user session. The other solution is to forget MySQL and compile PHP with 'mm' shared memory support, and use the mm storage handler for sessions, which accomplishes the same thing without using a database)


Really, though, PHP is already a high-performance platform. It is very well optimized for speed. The main thing to think about is scaleability, and your own architecture:

Architecture:

- Are you repeating any code blocks that you could put into a standard include?
- Are you loading more code than you need at any one time (conditional includes are a great thing)?
- Is your design modular, so that similar things are handled by the same function/class, etc...? (This way, you can optimize one function and your whole site will speed up.)

Scaleability:

Scaleability is still a bit of an issue with PHP. There are a couple interesting add-ons available, such as http://www.php.net/msession (clustered session daemon), and SRM (www.vl-srm.net). Other than this, you have to think about how your application can be run on multiple servers, using standard clustering technology. The simplest method is to use something like msession, or to store sessions in a central database, and then use multiple front-end webservers, and one master database server (which can be clustered/replicated according to the DBMS's abilities.) This way, your front-end webservers only contain code, without needing to maintain ANY data persistence, since that is handled by the database, for application data AND for session data. ON the other side, the SRM system actually allows for 'back-end' PHP scripts, which run independently of an HTTP request on the server, but which provide business logic and database pooling to the PHP front ends. I'm sure there will be a lot more work done in both of these areas during the coming year.

Good luck

(P.S. Hello my friend JD ;-)... )
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now