File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change 11<?php
22namespace Embed \ImageInfo ;
33
4- use Embed \ ImageInfo \ ImageInfoInterface ;
4+ use GuzzleHttp \ Pool ;
55
6- /**
6+ /**
77 * Class to retrieve the size and mimetype of images using Guzzle5
88 */
99class Guzzle5 implements ImageInfoInterface
@@ -14,22 +14,30 @@ class Guzzle5 implements ImageInfoInterface
1414 public static function getImagesInfo (array $ urls , array $ config = null )
1515 {
1616 if ($ config === null || !isset ($ config ['client ' ]) || !($ config ['client ' ] instanceof \GuzzleHttp \Client)) {
17- throw new RuntimeException ('Guzzle client not passed in config. ' );
17+ throw new \ RuntimeException ('Guzzle client not passed in config. ' );
1818 }
1919
2020 $ client = $ config ['client ' ];
21- $ result = [ ];
2221
22+ // Build parallel requests
23+ $ requests = [];
2324 foreach ($ urls as $ url ) {
24- $ response = $ client ->get ($ url ['value ' ]);
25+ $ requests [] = $ client ->createRequest ('GET ' , $ url ['value ' ]);
26+ }
27+
28+ // Execute in parallel
29+ $ responses = Pool::batch ($ client , $ requests );
2530
31+ // Build result set
32+ $ result = [];
33+ foreach ($ responses as $ i => $ response ) {
2634 if (($ size = @getimagesizefromstring ($ response ->getBody ())) !== false ) {
2735 $ result [] = [
2836 'width ' => $ size [0 ],
2937 'height ' => $ size [1 ],
3038 'size ' => $ size [0 ] * $ size [1 ],
3139 'mime ' => $ response ->getHeader ('Content-Type ' ),
32- ] + $ url ;
40+ ] + $ urls [ $ i ] ;
3341 }
3442 }
3543
You can’t perform that action at this time.
0 commit comments