Go Premium for a chance to win a PS4. Enter to Win


Highperformance with PHP???

Posted on 2002-07-24
Medium Priority
Last Modified: 2009-12-14

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?
Question by:delphiheaven
LVL 40

Accepted Solution

Richard Quadling earned 100 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.


Assisted Solution

dkjariwala earned 100 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 !!!

Expert Comment

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:


- 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 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 ;-)... )

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

783 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