title: How to send big data to API in laravel?
body: <pre><code>public static function send()
      {
          $products = Product::where('active', 1)-&gt;get(['id_product', 'price', 'reference'])-&gt;load(['images', 'lang']);
          // loop for all products and sending to API
          $number_of_products = count($products);
          $start = 0;
          $end = 70;
          for ($a = 0; $a &lt; ceil($number_of_products/70); $a++) {
              for ($i = $start; $i &lt; $end; $i++) {
                  // loop for all images in product
                  $count = count($products[$i]-&gt;images);
                  for ($k = 0; $k &lt; $count; $k++) {
                      $id = (string)$products[$i]-&gt;images[$k]-&gt;id_image;
                      $products[$i]-&gt;images[$k]-&gt;id_image = 'https://somesite.com/img/p';
                      $length = strlen($id);
                      // loop for every digit of id_image
                      for ($d = 0; $d &lt; $length; $d++) {
                          $products[$i]-&gt;images[$k]-&gt;id_image = $products[$i]-&gt;images[$k]-&gt;id_image . '/' . $id[$d];
                      }
                      $products[$i]-&gt;images[$k]-&gt;id_image = $products[$i]-&gt;images[$k]-&gt;id_image . '/' . $id . &quot;.jpg&quot;;
                      $images[] = $products[$i]-&gt;images[$k]-&gt;id_image;
                  }
                  $products[$i]-&gt;images[0] = $images;
                  $product = [
                      'code' =&gt; $products[$i]-&gt;reference,
                      'name' =&gt; $products[$i]-&gt;lang-&gt;name,
                      'price' =&gt; round(($products[$i]-&gt;price) * 13200, -2),
                      'quantity' =&gt; 1,
                      'description' =&gt; $products[$i]-&gt;lang-&gt;description,
                      'images' =&gt; $products[$i]-&gt;images[0],
                      'url' =&gt; 'https://avtech.uz/ru/' . $products[$i]-&gt;id_product . '-' . $products[$i]-&gt;lang-&gt;link_rewrite . '.html',
                  ];
                  $array_of_products[] = $product;
              }
              // Send 50 products to API
              $response = Http::withToken('token')-&gt;post('https://example.com/upload', [
                  'company_id' =&gt; ******,
                  'products' =&gt; $array_of_products
              ]);
              if ($response-&gt;failed()) {
                  Log::channel('send_products_to_pc')-&gt;info('Failed: ', [$response]);
              } else {
                  Log::channel('send_products_to_pc')-&gt;info('Success: ', [$response]);
              }
              $start = $start + 70;
              $end = $end + 70;
          }
  }
  </code></pre>
  <p>HELP PLEASE! What and how can I make this function work successfully.
  Getting &quot;504 Gateway Time-out&quot; - in Postman
  &quot;Allowed memory size of 134217728 bytes exhausted&quot; - in laravel.log.
  I don't want to increase memory_limit because memory leak might happen, and my script is not able to send 1300 products in 60 secs. In logs I can see that only 500-600 products are sent and then above mentioned errors are given.</p>