Sizzling Upload Progress Bar in PHP with APC, Part 1: APC Installation

After some series of “political” technical notes, I think it’s the right moment to supply some more technical posts to fellow developers. This time I will write about creating sizzling upload progress bar in PHP. In the past, there had been heated debate in PHP internal list about RFC 1867 implementation on PHP core code. If you were there, you might still remember that we had to patch the file main/rfc1867.c and some other files and then recompile PHP to get the upload progress bar hack working. Some harsh critics even mentioned that without the built-in capability of upload progress, PHP was years behind Java and Perl and lacked its capability as a web programming language.

Fortunately, since PHP 5.2 (especially after PHP 5.2.6 release), showing upload progress is not a big deal in PHP. Thanks to APC developers -mostly are also core PHP developers- who contributed to changes in APC that led to the availability of this long-waited feature. With APC we’ll be able to track the progress of file upload and provide our users better convenience when using our application.

Still, APC is not a part of core PHP shipped as a bundled package. We need to install it manually. In Windows, we can simply load the dll file to get it working. However, Linux users may need some pointers about how to install and enable this package. Hence, I will provide some guide for APC installation which was tested on veteran RHEL 4 and energetic young Fedora 10. So, let’s just go to the installation part.

Prerequisites:
Basic knowledge of Linux, access to root shell, yum installed on the machine

Installation steps:
1. Installing APC package with yum.
a. Lucky Luke installation
In this type of installation, we will try to install APC as php-apc package. If you are successful to run the following two commands, you can consider yourself lucky and simply proceed to step 2.

root#yum update php
root#yum install php-apc

After running the last command, you may realize how the path of your installation was destined. If you see this message on the console “No package php-apc available.” you were destined to do the type b installation instead.

b. Donald Duck installation
We have to do some more extra effort just like how Donald has to struggle against his misfortune. However, this type of installation offers more benefit for you when you decide to install more packages from PECL in the future. Different with previous installation in which we try to download php-apc package from the OS repository, in this installation, we will use pecl, a helper tool from PHP which is used to download and compile community extensions not shipped with default bundled package.
Please type the following commands on the console subsequently.

root#yum update php
root#yum install php-pear
root#yum install php-devel
root#yum install httpd-devel
root#pecl install apc

Note: when you’re asked to install APC with Apache apxs, just say yes.

2. Verifying the compiled apc.so module is located in the same directory with other PHP modules.
In some cases, the shared library apc.so created from step 2 was put in another directory which is different with location of the rest of php modules. You need to verify that this library is indeed integrated with its peers in the same directory. An example of verification is provided as the following:

root#locate php/modules
->For example, results show that the modules are located in /usr/libr64/php/modules/*
root#locate apc.so
->For example, results show that the module is located in /usr/lib64/20060613/apc.so
//Move apc.so to the directory where other php modules reside
root#cp -f /usr/lib64/20060613/apc.so /usr/libr64/php/modules/

3. Creating apc.ini entry or updating php.ini
We can create a new ini file called apc.ini and then put apc related configurations in this file. We can also simply append entry to php.ini. The commands below show the creation and updating of apc.ini
root#echo “extension=apc.so” > /etc/php.d/apc.ini
root#vi /etc/php.d/apc.ini


When we are modifying apc.ini, verify that it contains minimum configuration like below
;Load APC extension
extension=apc.so
;Other configurations
apc.rfc1867=on

4. Restarting Httpd daemon
root#/etc/init.d/httpd restart

5.Testing if everything is working as expected
Run php command (line) and check if APC is now part of it.
root#php -i |grep apc
//Or
root#php -r “phpinfo();” |grep apc

Congratulations. You have just installed APC and armed your PHP with more deadly bullet. Later, we will discuss about how to use APC to build our sizzling upload progress bar.

0 Responses to “Sizzling Upload Progress Bar in PHP with APC, Part 1: APC Installation”


  1. No Comments

Leave a Reply






Worth Trying

Subscribe to RSS

  • Subscribe via Feed Burner