pressbooks / ideas

Ideas for Pressbooks.
GNU General Public License v3.0
12 stars 4 forks source link

Sending download requests in parallel #21

Open dac514 opened 6 years ago

dac514 commented 6 years ago

Feature Scope

Feature Description

Pressbooks has a few fetchAndSaveUniqueImage methods using WordPress download_url. Ie.

\Pressbooks\Modules\Import\WordPress\Wxr::fetchAndSaveUniqueImage
\Pressbooks\Modules\Import\Html\Xhtml::fetchAndSaveUniqueImage
\Pressbooks\Cloner::fetchAndSaveUniqueImage

Sending many HTTP requests serially (one at a time) can cause an unnecessary delay in a script's execution. Each request must complete before a subsequent request can be sent. By sending requests in parallel, a pool of HTTP requests can complete at the speed of the slowest request in the pool, significantly reducing the amount of time needed to execute multiple HTTP requests.

These methods could be refactored. Break the caller into chunks of ~4 and then use Guzzle to download ~4 images at at time. Guzzle provides a wrapper for the curl_multi functions in PHP.

Feature Use Case

Faster cloning and importing of books with lots of images.

Other Notes

dac514 commented 4 years ago

Could also be done using "Async HTTP/1.1+2 client for PHP based on Amp"