Converting caffeine to code, shooting pics, and cruising the roads of life.

Apr 16th, 2006  Apr 16th, 2006

High Traffic Web Development

Over the past week and a half, I have been in the process of reading up on developing for high traffic sites. It is very interesting that it only requires small optimizations here and there.

One thing I’ve found in common with all large sites and that should be pretty obvious, is a PHP compiler cache and some type of caching system. Some of the more popular ones are APC, Bware Afterburner, Turck MMCache, and the Zend Accelerator. PHP caching systems are easy to write and can speed up template calls a ton.

You can speed up your site by using output buffering. What this does is use writev() instead of write(). The write() calls were sent to apache as 4kb buffers, where as the writev() calls aren’t.

Another speed up can be accomplished by setting Apache’s SendBufferSize to PageSize. This allows the page to be handed over to the kernel, to be sent, without blocking.

To reduce bandwidth, you may want to look into gzipping the contents of your page. I have seen this shrink 80gb backups down by almost a third the size, except for when most of the contents were images. So you should gain a lot for this if you can afford the overhead of the operations to compress your data.

There are also some simple thinks you can do to speed up your code. To speed up database calls, only query for that data you need. No need to SELECT * when you only need to SELECT id. You should also only query a table once. Get the data you need from it and store it, don’t query it again.

If you are using PHP5 or higher, you may also want to use MySQLi. This new MySQL API is much faster than the old API and includes both a functional and OOP interface. Most applications can be easily converted to use it. Plus, you get support for prepared statements and bind statements.

Optimization can also be made during the design of your database. Make sure you realize the differences between MyISAM and the InnoDB storage engines. MyISAM is very efficient for either very high volume writes or reads, but has table level locking. InnoDB has non-locking reads and row level updates, plus high concurrency.

You may also want to cache query results if they are not expected to update as often. An example I often use for this is CMS systems. Why query all of the blocks you want on one page, when you can cache the results of the original query for 6 hours and have them quickly accessible? Plus, if the owner of the site changes them, just clear the cache…

Now, back to what I’ve been up to. Besides reading up on the above, I have also been messing with my new project for the last two weeks straight. It is amazing how many hacks IE5-IE6 requires. I know I’ve used at least four to get my new site to display correctly. While the thing worked in Firefox, Safari, Epiphany, Konqeror, Opera, and IE7 the _whole_ time.

I hope most people will like the design though. I have shown it to around 20 people on IRC, and only one person hasn’t liked it a lot. So I would say I’ve done pretty good considering this was the first site I had designed entirely in Photoshop and then converted it to CSS/XHTML by hand. The core work for this new project starts this week and will probably continue for the next few months to a year.

Reference for high volume PHP:

9 Responses to “High Traffic Web Development”

  1. Hubert Roksor says:

    Well, thanks for this nice article but I think you should reconsider your tip about “include_once/require_once”.

    First of all, what files are best included only once? files containing classes and/or functions. So you’d better check for their existence with class_exists()/function_exists() instead of including them blindly.

    Second and most importantly, include_once/require_once are a lot slower than their counterparts (assuming you use an opcode cache). See for a better explanation :)

  2. Cody Mays says:

    Thanks, I’ll update the article. I can see why now. :thumbup_tb:

  3. I see, its quite useful. tips are really useful

  4. Hacks says:

    Great quality stuff.

  5. Levitra. says:


    Levitra. Levitra…..

  6. Simply want to say your article is as astounding. The
    clearness in your post is just spectacular and i could assume
    you’re an expert on this subject. Fine with your permission let me to grab your feed to keep updated with forthcoming post.

    Thanks a million and please continue the gratifying work.

  7. Crucial aspects of games are objectives, principles, concern, and
    conversation Games usually require sometimes equally, and mental or bodily excitement.
    Several games help serve as being a kind of exercise, produce practical
    skills, or else execute an informative, simulational, or psychological role.
    Games including hide-and- tag or seek do not utilize any resource that is obvious; relatively,
    the environment defines their interactivity.

  8. StevenDrot says:

    Невредно бы описать своими впечатлениями касательно путешествия по Европе.Впечатления не о знаменитостях и схожем, а о проституции и еёпрофилях.не секрет среди территорий земель пребывавшего СССР, а вдобавок на в Югославии, проституция абсолютно ликвидирована и гоняется по закону. этого не скажешь относительно земли Западной и Средней Европы. В этом ракурсе государства дробятся на 2 категорий- где без исключения легальна проституция и інтим услуги в разных формах индивидуалки Москвы, и где древнейшая профессия дозволена но запрещены бордели и сутенерство. к первой части свойственны ФРГ и Чехия. Ко вторым – Испания. первый вид – среди родоначальников секс-туризма, и собственно в те страны оптимально нестись из-за такого дела .

  9. Awsome site! I am loving it!! Will come back again. I am
    taking your feeds also

Leave a Reply