V
V
Volodymyr2020-12-30 17:13:26
Laravel
Volodymyr, 2020-12-30 17:13:26

How to send more than 1000 HTTP requests and get a fast response?

problem:

How to send more than 1000 HTTP requests and get a response quickly?
So far I have this code:

$contacts = Contacts::all();
        foreach ($contacts as $contact) {
            $response = Http::get('https://site.com/api/status', [
                'key' => $contact->key,
                'email' => $contact->email
            ]);
            $response = json_decode($response);
            $status = (isset($response->result->status) ? 'Yes' : 'No');
  
      $sts = $this->find($contact->id);
            $sts->status = $status;
            $sts->save();
        }

        return response()->json(['success' => 'Status Ok'],200);

But it takes a very long time, is it possible to send requests faster somehow and get an instant response?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-12-30
@volodyalesha86

Use Guzzle without Laravel wrapper in competitive mode .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question