php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57611 Problem while simultaneous upload
Submitted: 2007-04-05 18:43 UTC Modified: 2007-08-18 06:47 UTC
From: offset at galvanet dot com Assigned:
Status: Not a bug Package: uploadprogress (PECL)
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
 [2007-04-05 18:43 UTC] offset at galvanet dot com
Description:
------------
On the same server, uploading one file works fine.
If you try to upload 2 files at the same time, the last one call to uploadprogress_get_info return that the file is finished. And the first one is frozen until the second upload finished.

I found a ticket about multi-threading issues. However, I tested with apache 1.3, and the problem is the same.
As far as I know, apache 1.3 is a pre-forking server, not a threaded one.

Reproduce code:
---------------
I use the same code as :

http://php5.bluga.net/UploadProgressMeter/demo.php

I checked that the ID is well passed. It's seems ok.
But the return value is not right.

Open two browsers, put a 40M file, and start upload it.
In the second browser, put a 2M file, and upload it.
The 2M file will be directly a 100% and the 40M will be frozen until the 2M will be really finished.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-06 12:50 UTC] akayami at gmail dot com
I've experienced the same problem, while trying to have 2 (or more) simultaneous upload progress bars. (apache2 + php 5.2.1) Just to add to what the previous post said, it appears the problem is related to 2 instances of uploads within the same session. I was able to have 2 progress bars working in 2 different browsers (ie7 and ff2), but not in 2 instances of the same browser.
 [2007-07-17 05:09 UTC] chregu@php.net
Are you sure, you have a different ID for both uploads?
 [2007-08-17 20:14 UTC] goran at extensionsforjoomla dot com
I have the same experience on Fedora 4, Apache 2+ and PHP 5.2.3

Function uploadprogress_get_info() is returning in index 'bytes_total' total for all files submitted e.g. if there are three files submitted with id's 2648993,44167109 and 32898265 and size respectively 1.1MB, 1.2MB and 1.3MB when $tmp = uploadprogress_get_info($upId) is executed value of $tmp['bytes_total'] would be 3.6MB and not 1.1MB.

Off course if there is single upload or single graph/info bar displaying overall progress this does not make a problem but if one would like to have separate graph/info bar for each file submitted...

Anyways I don't see a point of having separate graph/info bar for each file submitted since files are uploaded consecutively and not simultaneously. Having this in mind it appears to me that it would be more efficient to have one id per form and to track overall progress.
 [2007-08-18 01:41 UTC] chregu@php.net
You do have more than one id per form? How should that work ? 

I don't see the problem here.
 [2007-08-18 06:44 UTC] goran at extensionsforjoomla dot com
Thank you for prompt replay.
Yes, I do have id for each file submitted. As far as I could understand that's how it should be. I am having hidden input field before each file input field. Each hidden input field is having unique id.
My first idea was to have graphic bar for each file submitted but that does not work. Let's use the same example as in my previous post: The graphic bar corresponding to the first file would start and would go to approx 30.5%. Than the second one would start from the point where the first one stopped and will continue to approx 63.7% where it would stop and the third one would start from that point and continue to 100%. This is not what I've expected. It is obvious that such behavior is result of 'bytes_total' value which is giving total of all files submitted and not total bytes of file tied with particular id. 
Of course using one id for entire form is not solution since the graph bar would start and stop when upload of file tied to that id starts/stops.
I've finally realized that there is no point in having graph bar for each file submitted since files are not simultaneously uploaded. Having multiple graph bars will not improve user experience since only one graph bar would be active at the moment.
The only seamless way to do it was to monitor all files submitted and use one graph bar updated with currently active file upload.
On server side:
  public function getUploadStatus($post) {

    foreach($post->offsetGet('uploadids') as $id => $upId) :
      $respond = new stdClass();

      $tmp = uploadprogress_get_info($upId);

      if ($tmp['bytes_total'] < 1) :
        $percent = 0;
      else :
        $percent = round($tmp['bytes_uploaded'] / $tmp['bytes_total'] * 100, 2);
        sleep($tmp['est_sec'] / 33);
      endif;

      if ($percent == 100) :
        $respond->message = 1;
        $respond->uploadids = $upId;
        $this->_ret[$id] = $respond;
        continue;
      endif;

      $eta = sprintf("%02d:%02d", $tmp['est_sec'] / 60, $tmp['est_sec'] % 60 );
      $speed = $this->_formatBytes($tmp['speed_average']);
      $current = $this->_formatBytes($tmp['bytes_uploaded']);
      $total = $this->_formatBytes($tmp['bytes_total']);

      $respond->message = "$eta left (at $speed/sec)	$current/$total($percent%)";
      $respond->percent = $percent;
      $respond->uploadids = $upId;
      $this->_ret[$id] = $respond;
    endforeach;
    return $this->_ret;  
  }
On client side:
function callback_uploadStatus(result) {
  if (uploadStatus == 0) {
    var progressBar = document.getElementById('progressBar');
	for (i = 0; i < fileNum; i++) {
	  if (result[i].percent > 0) {
        var message = document.createTextNode(result[i].message);
        progressBar.style.width = result[i].percent + '%';
        progressBar.nextSibling.removeChild(progressBar.nextSibling.lastChild);
        progressBar.nextSibling.appendChild(message);
	  }
	}
    agent.call('files.php', 'getUploadStatus', 'callback_uploadStatus', Data);
  } else {
    var wrapper = document.getElementById('uploadStatusDiv');
	wrapper.removeChild(wrapper.lastChild);
	wrapper.appendChild(elem('p',
    {}, {}, 'Uppload finished!'));
  }
}
There is obvious overhead: On each call all id's are evaluated on both sides.
Please let me know if I am not clear and I would setup an example.
 [2007-08-18 06:47 UTC] chregu@php.net
There has to be only one ID per form and not one per file-
upload-field...

I still don't see the problem
 [2007-08-24 07:07 UTC] goran at extensionsforjoomla dot com
You are absolutely right: there is no problem. It's my mistake. One ID per form and it works like charm. :)
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jan 17 18:01:24 2020 UTC