uploadprogress requires pecl extensions (uploadprogress or apc) but my hosting provider (a2hosting) does not install pecl modules (only pear).

so to fix that, i've heard perl could be capable

and it is, as it turned out

works like that:

  1. add the following line to your .htaccess, above "Rewrite URLs of the form 'x' [...]":

    RewriteRule ^filefield/ahah/pictures/field_pictures/.* filefield-proxy.pl?q=$0 [L,QSA]

  2. put the following code in a file called filefield-proxy.pl in the same directory, make it executeable
    #!/usr/bin/perl
    
    map { $ENV{$_} =~ s|/[^/]*$|/index.php| } ('SCRIPT_NAME', 'SCRIPT_FILENAME');
    open (PHP, "|/usr/bin/php", @ARGV ); # or maybe try "php-cgi" - HAS to output HTTP headers !
    while (<>) {
            print PHP;
            unless ( $s ) { $s++ if /^Content-Disposition: form-data; name="UPLOAD_IDENTIFIER"/; }
            else          { if ( $s == 1 ) { $s++ if m"\n"; } else { $/="\r\n"; chomp; $uid = $_; last; } }
    }
    die "Premature end of input" if eof;
    use IO::Socket::UNIX;
    $srv = new IO::Socket::UNIX ( Listen => 1, Local => "/tmp/perluploadprogress$uid" );
    die "Can't create UNIX Socket" unless $srv;
    $srv->blocking(0);
    while (1) {
            if ( $cln = $srv->accept ) {
                    $cln->print ( "$tr / " . $ENV{'CONTENT_LENGTH'} );
                    $cln->close;
            }
            last unless ( $nr = read STDIN, $in, 4096 );
            print PHP $in;
            $tr += $nr;
    }
    unlink $srv->hostpath;
    $srv->close;
    close PHP;
    wait;
    
  3. apply the follwing patch to the filefield-6.x-3.7 module
    diff -ru filefield/filefield.module filefield-hack/filefield.module
    --- filefield/filefield.module  2010-06-29 21:37:29.000000000 -0400
    +++ filefield-hack/filefield.module     2010-08-09 23:48:53.000000000 -0400
    @@ -629,6 +629,15 @@
           $progress['percentage'] = round(100 * $status['current'] / $status['total']);
         }
       }
    +  elseif ($implementation == 'perl') {
    +    if ($ipc = socket_create(AF_UNIX, SOCK_STREAM, 0)) {
    +      if (file_exists($file = "/tmp/perluploadprogress$key") && socket_connect($ipc, $file) && ($pro = socket_read($ipc,512,PHP_NORMAL_READ))) {
    +         list($r, $t) = explode('/', $pro);
    +         $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($r), '@total' => format_size($t)));
    +         $progress['percentage'] = round(100 * $r / $t);
    +      }
    +    }
    +  }
    
       drupal_json($progress);
     }
    @@ -636,7 +645,7 @@
     /**
      * Determine which upload progress implementation to use, if any available.
      */
    -function filefield_progress_implementation() {
    +function filefield_progress_implementation() { return 'perl';
       static $implementation;
       if (!isset($implementation)) {
         $implementation = FALSE;
    diff -ru filefield/filefield_widget.inc filefield-hack/filefield_widget.inc
    --- filefield/filefield_widget.inc      2010-06-29 17:38:10.000000000 -0400
    +++ filefield-hack/filefield_widget.inc 2010-08-09 20:30:08.000000000 -0400
    @@ -342,7 +342,7 @@
       if ($progress_indicator != 'throbber' && $implementation = filefield_progress_implementation()) {
         $upload_progress_key = md5(mt_rand());
    
    -    if ($implementation == 'uploadprogress') {
    +    if ($implementation == 'uploadprogress' || $implementation == 'perl') {
           $element['UPLOAD_IDENTIFIER'] = array(
             '#type' => 'hidden',
             '#value' => $upload_progress_key,
    

    enjoy... ! (and maybe integrate the code properly...)

    cheers

    patrick

CommentFileSizeAuthor
#2 filefield-hack.diff2.76 KBpatrick2000
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Category: bug » feature
Priority: Minor » Normal
Status: Needs review » Active

I don't really see how this is a "bug", although I find it interesting. I think that this requires enough effort and I'd be so unlikely to test it that it should be it's own module, as the http://drupal.org/project/filefield_nginx_progress was.

patrick2000’s picture

Category: feature » bug
Priority: Normal » Minor
Status: Active » Needs review
FileSize
2.76 KB

Ok, ignore the first post - now it works (again ... (removing the "\n" output from perl and then reading with PHP_NORMAL was not so clever as php kees reading forever that way))

I moved the perl script into the module directory and created a single patch for the issue

the .htaccess line of course still has to be added manually ... i'm not sure if there is a way to avoid that ... :-/

patrick2000’s picture

Category: bug » feature
patrick2000’s picture

.htaccess:

# Maybe that's also needed in certain configurations
AddHandler cgi-script .pl

RewriteRule ^filefield/ahah/pictures/field_pictures/.* sites/all/modules/filefield/up-proxy.pl?q=$0 [L,QSA]

still above "Rewrite URLs of the form 'x' [...]"

thanks for the feedback quicksketch

i get you about the seperate module ... let's see if and when i'll make the effort ....

"bug" came out of a tesing kind of mood ... think ubuntu bug #1 (microsoft has too big a market share)

patrick2000’s picture

Title: Upload progress through Perl instead of PHP » uploadprogress requires pecl extensions
Status: Fixed » Needs review

Well, I made it a module now - similar like nginx_progress.

The mod_rewrite hack in .htaccess is not needed any more and (with my hosting company at least) the module works without further modifications after installing and enabling.

I wrote a README.txt which covers a lot of possible issues. Would be great if somebody could make use of and/or test it!

I'm not sure weather am I really supposed to start a new /project/ for this - applying for cvs access, be maintainer et. all... ??

Quicksketch, how about a submodule, like filefield_meta ?

If I need to upload that stuff myself and be maintainer, don't expect it to happen before drupal has switched to git. No way that I'm going with cvs for this. :-)

quicksketch’s picture

Yes I meant that a new project is created and you maintain it. Since I'm not familiar at all with the approach you've used and there's no way that I'd use it over the built-in PHP upload progress. At the very least you might put it up on Github if you're not going to trouble with CVS.

patrick2000’s picture

ok fine ... that git thing is here finally: http://git.pfeifer.ch/ ... get it!

cloning also possible through http (new, fast backend) - e.g. git clone http://git.pfeifer.ch/drupal/modules/filefield_perlprogress.git - u can copy the links for cloning directly from the web ...

eehr ... and i'd still prefer to be a submodule ... so many other modules have a contrib/ subdirectory and such things - ehr, yes - filefield as well ...

I could still maintain it. Would just need to have relevant e-mails from the issue queue forwarded to me - i'll show up and try my best to help anybody. But I really don't see why I should become a /project/ maintainer for those ~ not even 50 lines of code.... sorry.

Oh... did you see the tree snapshot feature in gitweb? http://git.pfeifer.ch/drupal/modules/filefield_perlprogress.git/snapshot... should allways get you the latest version.

cheers

quicksketch’s picture

Title: uploadprogress requires pecl extensions » Upload progress through Perl instead of PHP
Status: Needs review » Fixed

At this point we're moving modules OUT of the FileField project, since it is going to be discontinued in Drupal 7 (now that it is in core). The FileField Meta module will be merged with GetID3. The best long-term route for an alternative upload progress bar is a separate contrib module. Thanks for making it publicly accessible. I'd recommend that you make a project page for it here on Drupal.org and point over to it, otherwise people won't be able to find it.

Title: uploadprogress requires pecl extensions » Upload progress through Perl instead of PHP
Status: Needs review » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ClearXS’s picture

Interesting... Just start learning about Perl and then immediate the question arises if Drupal is outdated as it only builds upon PHP, not upon Perl that's just there to be used!

Of-course it sometimes needs server installs or initialization. Just start trying to install Foswiki (Twiki) that might be the best wiki program and needs some extra work to get it running. But with that extra work it probably runs standard what drupal does not..?

And it has more features when using doc files instead of MySQL, but in Drupal still a lot is done with the file system!

http://search.cpan.org/
http://search.cpan.org/search?query=drupal&mode=all

Excuse me to drop into the topic, but there are not many topics about Perl at drupal.org...