title: json_decode - how to speed it up in GuzzleHttp asnyc request
body: <p>In my application I'm using the GuzzleHttp library, but it not probably the problem, but is't good to say it.</p>
  
  <p>Every minute (using cron) I need to get data from 40+ addresses, so I took GuzzleHttp lib to be fast as possible.</p>
  
  <p>Guzzle code:</p>
  
  <pre><code>$client = new Client();
  $rectangles = $this-&gt;db-&gt;query("SELECT * FROM rectangles");
  
  $requests = function ($rectangles)
  {
      foreach($rectangles as $rectangle)
      {
         // some GEO coords (It's not important)
         $left   = $rectangle["lft"];
         $right  = $rectangle["rgt"];
         $top    = $rectangle["top"];
         $bottom = $rectangle["bottom"];
  
         $this-&gt;indexes[] = $rectangle;
  
         $uri = "https://example.com/?left=$left&amp;top=$top&amp;right=$right&amp;bototm=$bottom";
              yield new Request("GET", $uri);
     }
  </code></pre>
  
  <p>};</p>
  
  <pre><code>$pool = new Pool($client, $requests($rectangles), [
      'concurrency' =&gt; 5,
      'fulfilled' =&gt; function ($response, $index) {
          $resp   = $response-&gt;getBody();
          $carray = json_decode($resp,true);
  
          if($carray["data"] != null)
          {
              $alerts = array_filter($carray["data"], function($alert) {
                  return $alert["type"] == 'xxx';
              });
  
              $this-&gt;data = array_merge($this-&gt;data, $alerts);
              $this-&gt;total_count += count($alerts);
          }
      },
      'rejected' =&gt; function ($reason, $index) {},
  ]);
  
  $promise = $pool-&gt;promise();
  $promise-&gt;wait();
  
  return $this-&gt;data;
  </code></pre>
  
  <p>Of course i made a benchmark of this. </p>
  
  <pre><code>1. getting data from another server 0.000xx sec
  2. json_decode 0.001-0.0100 (this is probably the problem :-()
  </code></pre>
  
  <p>The entire code takes about 6-8 seconds. It depends on the amount of data that is on a remote server.</p>
  
  <p>All the time I thought Guzzle performs request asynchronously, so it will takes time as the longest request.</p>
  
  <p>(slowest request = 200 ms == all request = 200 ms) - But this is probably not true! Or I am doing something wrong.</p>
  
  <p>I used an associative array in json_decode (I feel that this is an acceleration of 1 sec (I'm not sure...)).</p>
  
  <p><strong>My question is, can I this code more optimize and speed it up?</strong></p>
  
  <p>I wish to make it fast as one the slowest request (0.200 sec).</p>
  
  <p>PS: The data that I'm getting from URLs are just long JSONs. Thanks!</p>
  
  <p>EDIT: I changed the 'concurrency' => 5 to 'concurrency' => 100 and now the duration is about 2-4 sec</p>