Forum Moderators: coopster

Message Too Old, No Replies

Minimizing PHP coding for effecient processing

Cleaning up code for load time and server processing time

         

Eric_Lander

1:39 pm on May 29, 2003 (gmt 0)

10+ Year Member



I've been making an attempt to learn more about PHP and mySQL integrations within the past few weeks, and I've been able to accomplish quite a bit thanks to the number os users here providing support.

I have effectively made the transition from running a static portal over to one served up through PHP. While the accessibility and content management aspects of the site have greatly improved, I have also begun to push the limitations of my hosting plan for a specific web site.

In particular, the amount of data transferred to through the account has increased some 30% on a daily basis compared to the averages from just one month ago. Traffic levels are very similar, as is the number of visitor sessions and page views. Essentially nothing has changed aside from the static pages are now generated in PHP.

Another aspect I've noticed, is the overall processing and load time for the user experience. Pages that once loaded quickly are lagging behind a second or two more than they once did. While that's not a long time in general, it is an incredibly long time for first time users of the site.

Because of these findings, I've begun researching various ways to decrease the amount of code needed to render the same results. Since I'm a newbie to PHP and mySQL connections, it is difficult for me to know where to look.

So, I'd like to see what some of the forum members here have learned over time when it comes to optimizing PHP scripting to enhance the user experience and server load.

Any suggestions or findings you'd like to share?

aspr1n

1:53 pm on May 29, 2003 (gmt 0)

10+ Year Member



Hi Eric,

My argument would be PHP is designed to be executed quickly so if its not, and assuming that you've followed good coding practices and your PHP environment is well implemented, don't try and minimise the use of your tool, just take a different approach.

This thread on scalability [webmasterworld.com] may help.

I am not sure what other tricks you may have already tried:

1. I personally don't know what effect things like loop unrolling can have - someone else care to comment?

2. Check out this page: xdebug.derickrethans.nl as it will allow you to profile you code and see where the delays are occuring.

asp

[edited by: jatar_k at 2:19 pm (utc) on May 29, 2003]
[edit reason] delinked [/edit]

BCMG_Scott

6:50 pm on May 29, 2003 (gmt 0)

10+ Year Member



Optimazation for MySQL - you'll want to learn and use the EXPLAIN command on all of your SELECT queries. Also, you'll want to learn when to use/build an INDEX and when not to.

The short answer on INDEXES is this: The more indexes you have the faster your SELECTS will run(unless you index every column), but the slower your INSERTS and UPDATES will run. Now that is a DRASTIC oversimplification, but you kind of get the picture. You can also build multi-column indexes as well and in some cases this may be a better choice than a single column index.

Scott Geiger

mavherick

7:49 pm on May 29, 2003 (gmt 0)

10+ Year Member



I've been using checkpoints in all my application design (be it php or any other language) for a while (somebody here mentionned it, can't rememeber who exactly..). Anyway, simply put, you keep track of the execution time at key points, then based on ip (i got a static one) it displays a detailed running time report.

After that you can easily pin-point the bottlenecks.

There's obviously other things you can do, but I guess that's a start.

mavherick