Slide 1

Slide 1 text

Upload Progress Bars & More Using pecl/uploadprogress Ben Ramsey
 benramsey.com

Slide 2

Slide 2 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE 2

Slide 3

Slide 3 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE 3

Slide 4

Slide 4 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE • Traditional approach is to use APC • Create a form field named APC_UPLOAD_PROGRESS at the top of your form • Use XHR to send the value of that field to a script that returns the progress of the upload • Stored in APC: § total, current, rate, filename, name, temp_filename, cancel_upload, done 4 Progress Bar With APC

Slide 5

Slide 5 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Progress Bar With APC 5

Slide 6

Slide 6 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Progress Bar With APC 6

Slide 7

Slide 7 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Problems With APC Approach • File upload takes place on one machine • Data in APC is local to a particular machine • Other machines can’t access the data stored in APC on the machine handling the upload • Requests for progress may not “hit” the same machine as the uploading file • Use “sticky” sessions on your load balancer • Or... use pecl/uploadprogress 7

Slide 8

Slide 8 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Progress Bar With pecl/uploadprogress • INI directive to choose where to store data: § uploadprogress.file.filename_template § Stores to /tmp/upt_%s.txt by default • Set this to central storage mount • Create a form field named UPLOAD_IDENTIFIER at the top of your form • Use XHR to send the value of that field to a script that returns the progress of the upload • Stored: § time_start, time_last, speed_average, speed_last, bytes_uploaded, bytes_total, files_uploaded, est_sec 8

Slide 9

Slide 9 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Progress Bar With pecl/uploadprogress 9

Slide 10

Slide 10 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Progress Bar With pecl/uploadprogress 10

Slide 11

Slide 11 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Problems With pecl/uploadprogress • Writing to disk rather than memory • If not using central storage, still restricted to one machine (use sticky sessions) 11

Slide 12

Slide 12 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE 12

Slide 13

Slide 13 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE 13 Reading File During Upload

Slide 14

Slide 14 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE Problems With Approach • Not yet part of pecl/uploadprogress • Writes file to temporary location in central storage as it’s uploaded • Reading from disk rather than memory 14

Slide 15

Slide 15 text

10-Oct-07 UPLOAD PROGRESS BARS & MORE For More Information... • pecl/uploadprogress: § http://pecl.php.net/package/uploadprogress • My uploadprogress_get_contents() patch: § http://benramsey.com/code/uploadprogress.diff.patch • My blog: § http://benramsey.com/ 15