Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Highperformance with PHP???

Posted on 2002-07-24
5
241 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:
Richard Quadling 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

856 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