Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
By jeremy at 2006-06-29 14:10
Features - LAMP Post
Written by Jeremy Garcia
As the LinuxQuestions.org (http://www.linuxquestions.org/) web site continues to grow, good performance remains vitally important. The August 2004 “Tech Support” demonstrated a couple of ways to optimize the Apache HTTP Server. The next few columns examine ways to enhance the performance of PHP applications.
It’s estimated that PHP, a recursive acronym that stands for PHP: Hypertext Preprocessor, is currently in use on tens of millions of domains. Moreover, PHP is becoming increasingly capable with each release of the language, and is now considered a viable option for enterprise applications. Companies like IBM, Oracle, and Yahoo! now support PHP in a major way.
PHP performance is a topic you’ll find widely discussed on the Internet. In addition to Google, http://talks.php.net/ is a great place to look for information on language-specific tweaks, such as disabling register_globals and building the interpreter properly. Here, let’s focus on application-specific tweaks and system-wide enhancements that boost performance.
memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. Available under the BSD license, memcached was originally written by Brad Fitzpatrick for LiveJournal and is available for download from http://www.danga.com/memcached/. memcached is meant to work in concert with something like the MySQL query cache, not replace it. The two implementations excel at vastly different things: memcached is an object cache, while MySQL provides a query cache.
As you may have guessed, memcached is extremely fast. It uses libevent, which provides a mechanism to execute a callback function when a specific event occurs on a file descriptor, to scale to any number of open connections. On a modern Linux system memcached utilizes epoll, is completely non-blocking for network I/O, ensures memory never gets fragmented, and uses its own slab allocator and hash table to achieve 0(1) virtual memory allocation.
Before installing memcached, download and install libevent (the latest version is available from http://www.monkey.org/~provos/libevent/) with the usual ./configure&&make&&make install sequence. Then download and unpack the memcached tarball, running ./configure&&make&&sudo make install to install memcached, too.
With memcached installed, start it using the following syntax:
This starts memcached as a daemon (–d) on the IP address and port specified with –l and –p, respectively, running as the user nobody (–u), allocating 32 MB for object storage (–m). You should adjust the amount of storage to suit your needs; many memcached installs run with 4 GB. Once you’re comfortable with your startup options, add the appropriate command to your startup scripts.
With memcached installed and running, it’s time to get PHP talking to the object cache. While multiple PHP API’s exists, the one in the PECL repository is recommended. If you’re running a newer version of PHP, installation is as simple as:
# pecl install memcache
If you are still running PHP4, you may need to use pear to perform the install instead of pecl. Or, if you’re more comfortable with a manual install, head over to http://pecl.php.net/package/memcache and download the extension from there.
If you’ve made it this far, you now have the full suite of PHP memcache functions at your fingertips. You can review those functions at http://us3.php.net/memcache. The latest version of the memcache PHP extension supports some advanced features, including distribution over multiple servers with loadbalancing and failover, automatic compression, and an extended statistics function.
Unfortunately, this is as far as general instructions can take you. From here, you need to profile your application, see what data it makes sense to cache, and then use the API to do so. Depending on your application, this can range from a trivial task to a major undertaking. The good news is that much of the complicated logic is abstracted away for you, so you can focus on the needs of your specific application. When utilized properly, memcached can make an astounding difference, and it’s well worth the initial work to get setup if you are experiencing any amount of strain on your database servers.
Fully optimizing your entire LAMP stack is no easy task, and proper optimization requires you to look at each component in detail. There is no panacea, and memcached is just one piece of the puzzle, albeit a piece that has worked extremely well for sites such as Slashdot, LinuxQuestions.org, and Wikipedia.
Next month’s column looks again at PHP optimization. Coming up, we’ll explore the installation of a PHP opcode cache.