|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 06:00:01 2025 UTC |
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.