Upload progress tracking in PHP5.2

Published November 28th, 2006

A couple of weeks ago I mentioned that PHP 5.2 would have support for tracking the progress of file uploads. However, when I went looking for signs of this new functionality I came away empty-handed and rather confused. It’s definitely there in the release notes, but I just couldn’t find any reference to it anywhere else.

So I posted a question to the PHP Internals mailing list, asking “where are the promised hooks for PHP upload progress monitoring?” and within a few hours I had a nice clear reply from none other than Rasmus Lerdorf himself:

They are C-level hooks.  The various storage mechanisms need to add support for them in order to expose them to userspace PHP.  I added support in pecl/apc, for example.


 (pick some random file in the 200k size range)

Source at:  http://progphp.com/progress.phps

Eventually we will see more extensions that manage server-side storage with support for the hooks.

…meaning that while in theory the functionality is there, it’s not exposed to ‘normal’ people — yet. There’s a proprietary but promising extension here, which might eventually make it into the PHP core (maybe). Until then (or until another similar patch gains acceptance) we’ll have to wait.

Oh and as a side-note, someone also posted a link to this extension that uses the upload hooks to allow you to scan files for viruses, during upload. Nice.

Get a Trackback link


  1. Russ on September 21, 2007

    I tried copying the source code above and I don’t get the same results. I am running php 5.2.3 with APC installed. The progress bar appears but shows no progress. Also, I get the following message when the process completes.


    Has anyone experienced this or know the solution to this problem?

  2. Me on February 11, 2008

    Just a response to Russ… although it’s a few months old.

    You need the json library installed in PHP as well. :-)

  3. Ichi on June 15, 2008

    I get the same output as Russ, and I have JSON installed – at least according to my phpinfo() dump. I was unable to install the ‘php5-json’ package, as it’s now a meta-package for ‘php5-common’. (i.e. You get it whenever php 5.2 is installed under Ubuntu.)

    I’ve been trying, somewhat in vain, to get this progress meter stuff working under a new Ubuntu 8.04 install. I had one working cleanly under 7.10, but no matter how much configuration I’ve compared, something seems amiss with the new versions of PHP, Apache, and friends.

    As described here: http://webreflection.blogspot.com/2007/10/upload-progress-bar-with-php5-apc-and.html
    (last anonymous comment from 13 May 2008), my setup is: Ubuntu 8.04, Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.1 with Suhosin-Patch mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g. Nevertheless, I can’t get the APC-based upload meters running.

    Any thoughts?

  4. Traveller on July 18, 2008

    Thanks a lot this tip!

    But it runs on servers without APC?

Leave a comment

Comment Policy: First time comments are moderated. Please be patient.