Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Monitoring File Uploads using Ajax and PHP

Installing APC

Before we can begin implementing our file upload monitor we must install the Alternative PHP Cache extension (APC). If you are using a UNIX based operating system, the simplest way to install APC is to use the PECL command line installer.

Specifically, you should use the following command:

Listing 1 Installing the Alternative PHP Cache (listing-1.txt)
# pecl install apc

Executing this command should result in the necessary files being downloaded, compiled and installed. You will then need to modify your php.ini file to load the extension. If you built PHP from source the typical location for php.ini is /usr/local/lib/php.ini. If you use FreeBSD and used ports to install PHP then php.ini can be found in /usr/local/etc/php.ini.

Listing 2 Enabling the APC extension in PHP on UNIX/Linux/FreeBSD (php.ini)
Note: You may need to specify the full path to this file (depending on your configuration).

If you are instead running PHP on Windows, the extension DLL file should already exist – it simply needs to be activated in the php.ini (typically in c:\windows\php.ini) file using a similar command to above:

Listing 3 Enabling the APC extension in PHP on Windows (php.ini)

Enabling File Upload Monitoring

Next the feature of APC that monitors file uploads must be activated. To do so, the apc.rfc1867 setting must be switched on.

Note: RFC 1867 is the document that describes how HTTP file uploads work. Refer to for more details.

Simply add the following line to your php.ini file.

Listing 4 Enabling File Upload Monitoring (php.ini)
apc.rfc1867 = On

Restarting Your Web Server

Once the changes described in this section have been made you must restart your web server. To do so you can type apachectl restart in UNIX or simply restart the Apache service in Windows.

After the web server has been restarted, confirm the changes by viewing the phpinfo() output for your web server. If all is working, there will be an APC section on this page (in which the apc.rfc1867 setting will be switched to On).

In This Article

Additional Files