im new in laravel im using Third Party API for sending sms notification, but Third Party API having some Down time so i need to refresh page ONCE OR TWISE to send notification, i that time get error on my website.
i need to auto send second attempt if get error and i dont what to show error in my site.
Error Im Getting
Illuminate\Http\Client\ConnectionException
cURL error 28: Failed to connect to api.gateway.in port 80: Timed out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
My controller
public function Store_Enrollment(Request $request)
{
$this->validate($request, [
'student_name' => 'required|string|max:255',
'phone_no' => 'required|string|max:10',
]);
$input['student_name'] = ucfirst ($request['student_name']);
$input['phone_no'] = $request->phone_no;
$redirect = Student::create($input);
Http::post("http://api.gateway.in/sendmessage.php?user=XXX&password=XXX&mobile=$redirect->phone_no&message=thank you $redirect->name,");
return redirect('home' . thank you);
}
CodePudding user response:
HTTP client has a retry
function, so you could do the following:
Http::retry(3, 30)->post("some_stuff");
where the 1st parameter is the number of retries and the 2nd are the seconds between the retries which is optional.
So the above will retry 3 times with 30 seconds in between the requests.
You might don't want to throw and an error but you can't retring for an eternity so i'd suggest to use a try
and catch
block so the app can fail gracefully. Error handling is a big deal.