Book Image

eZ Publish 4: Enterprise Web Sites Step-by-Step

Book Image

eZ Publish 4: Enterprise Web Sites Step-by-Step

Overview of this book

eZ Publish provides developers with a structure to build highly impressive applications and then quickly deploy them into a live environment. eZ Publish is complex, with a steep learning curve, but with the right direction it offers great flexibility and power. What makes eZ Publish special is not the long list of features, but what's going on behind the scenes. Created specifically for newcomers to eZ Publish, and using an example Magazine web site, this book focuses on designing, building and deploying eZ Publish to create an enterprise site quickly and easily. This tutorial takes eZ Publish's steep learning curve head-on, and walks you through the process of designing and building content-rich web sites. It makes the unrivalled power and flexibility of eZ Publish accessible to all developers. The book is organized around technical topics, which are handled in depth, with a general progression that follows the learning experience of the reader, and features a single magazine web site project from installation to completion and deployment. This hands-on guide helps the reader to understand the Content Management System to create a web 2.0-ready web site by creating new extensions or overriding the existing ones. In turn, it helps you to become confident when working in the eZ Publish administration area and offers an environment in which you can practice while working through the chapters.
Table of Contents (20 chapters)
eZ Publish 4: Enterprise Web Sites Step-by-Step
Credits
About the Authors
About the Reviewer
Preface
Advance Debugging

Appendix A. APC Installation and Optimization

During the creation of a site, we discussed a lot of things not directly related to it, but very useful in our job. In this chapter, we will see how to apply some of these concepts and understand how the others work. We will also look at some of the best extensions developed by the eZ Publish community.

APC tuning for eZ Publish

We have discussed APC, both in the cache chapter and in the previous. Now, we will understand better what it is and how it works.

Opcode Cache

To publish the web pages, eZ Publish has to elaborate on a lot of data. In some cases, this work could turn out to be a CPU-eater and thus slow down the response of the server. For this reason, it is useful to install and use an opcode cache system such as APC. This kind of system will save the PHP intermediate code that is generated by the PHP interpreter in memory, and re-use it when called by the interpreter.

How does it work?

As we can see in the following schema, the page requests are first analyzed, to see if they are declared as either cacheable or not. If they are cacheable, the system will check to see if there is suitable content in the cache, or if it has to create (and save) a new one.

Installing APC

To install APC, we have to be sure that our Linux server has the necessary packages to compile it.

These packages are related to the building system (GCC, Make, Glibc, and so on), that is, the development headers for Apache and PHP.

If our distribution is a derivation of GNU Linux Debian (like Ubuntu), we can install it using apt-get, by using the root account or a user in the sudoers group.

sudo apt-get install build-essential
sudo apt-get install php5-dev apache2-dev

Otherwise, if we have a Red Hat based distribution (such as Fedora or CentOS), we have the building packages installed by default. We only need to install the PHP and Apache development packages, by using a root account.

yum install php-devel httpd-devel

Installing from sources

After we are sure that we have all of the required packages, we can execute the following commands from a shell, in order to download and compile APC from the source code:

cd /usr/local/src
wget http://pecl.php.net/get/APC
tar -xzf APC-x.x.x.tgz
cd APC-x.x.x
phpize
./configure enable-apc-mmap
make
sudo make install

PECL installation

Another way of installing APC is by using PECL. This is a module repository for PHP, with a lot of different modules. Moreover, when installed, PHP has a PECL shell command available by default, which can be used to install or remove modules.

As for the source code, we have to ensure that we have the PHP development packages before installing APC.

The installation should be done by a root user from the command line, by executing the following code:

pecl install apc

APC configuration

APC has a lot of features, all of them well explained in the online manual (http://php.net/manual/book.apc.php). We will now configure our installation to work with eZ Publish.

To do this, we have to create a file called apc.ini, and place it in the correct path in the base of the Linux flavor we are using:

  • On GNU Linux Debian, we will create the file in /etc/php5/conf.d/apc.ini

  • On Red Hat based distributions, we have to create the file in /etc/php.d/apc.ini

    Now, in the file we have to enter the following lines:

    # Load APC extension
    extension=apc.so
    apc.enabled = 1
    apc.shm_size=64
    apc.filters=cache
    apc.file_update_protection = "0"
    apc.include_once_override = "1"
    

Whereas the first two lines simply enable the module, the others are required to optimize APC for our purposes.

We will now describe this code, line by line:

  • apc.shm_size: This defines the size of each shared-memory segment, in MB.

  • apc.filters: This specifies a list of comma-separated values of regular POSIX expressions. If any pattern matches a source filename, that file will not be cached. In our case, we are configuring APC to not cache the eZ Publish cache.

  • apc.file_update_protection: The file_update_protection parameter is used to lock the file for a certain time slot. By default, this time slot is two seconds, but we can also deactivate it (with the 0 value) if we are sure that our file will be accessed (or modified) with atomic instructions (as rsync does).

  • apc.include_once_override: This value allows us to enable the optimizer for the PHP require_once() and include_once() functions, in order to avoid the expensive system call used.

APC GUI

If we install APC with PECL, we will find a file named apc.php in the /usr/share/php folder. This file can be used to analyze the APC works. To use it, we have to copy the file in the HTTP server directory (such as /var/www/) and then browse it using our preferred browser.

The result will be as shown here:

Other than the cache, with this script we can also check the memory usage to better configure the shm_size parameter for the server that we are using.

Performance

As a simple example, we will run the site with and without APC, on our development laptop, using ApacheBench Version 2.3 (http://httpd.apache.org/docs/2.2/programs/ab.html). Here are the results:

Without APC

With APC

Concurrency Level: 5

Time taken for tests: 15.880 seconds

Complete requests: 100

Failed requests: 43

(Connect: 0, Receive: 0, Length: 43, Exceptions: 0)

Write errors: 0

Total transferred: 3436775 bytes

HTML transferred: 3379675 bytes

Requests per second: 6.30 [#/sec] (mean)

Time per request: 794.005 [ms] (mean)

Time per request: 158.801 [ms] (mean, across all concurrent requests)

Transfer rate: 211.35 [Kbytes/sec] received

Concurrency Level: 5

Time taken for tests: 8.112 seconds

Complete requests: 100

Failed requests: 40

(Connect: 0, Receive: 0, Length: 40, Exceptions: 0)

Write errors: 0

Total transferred: 3436371 bytes

HTML transferred: 3379271 bytes

Requests per second: 12.33 [#/sec] (mean)

Time per request: 405.600 [ms] (mean)

Time per request: 81.120 [ms] (mean, across all concurrent requests)

Transfer rate: 413.69 [Kbytes/sec] received

By enabling APC, we can see that the execution time for running the tests is half, and that the requests for the second are twice that of the previous one.