我是 laravel 的新手,我使用第三方 API 發送短信通知,但是第三方 API 有一些停機時間,所以我需要重繪 頁面一次或兩次來發送通知,我那個時候在我的網站上出現錯誤。
如果出現錯誤,我需要自動發送第二次嘗試,并且我沒有在我的網站上顯示什么錯誤。
我得到的錯誤
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)
我的控制器
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);
}
uj5u.com熱心網友回復:
HTTP 客戶端有一個retry功能,因此您可以執行以下操作:
Http::retry(3, 30)->post("some_stuff");
其中第一個引數是重試次數,第二個是重試之間的秒數,這是可選的。
所以上面將重試 3 次,請求之間的間隔為 30 秒。
你可能不想拋出一個錯誤,但你不能永遠回滾,所以我建議使用 atry和catch阻塞,這樣應用程式就可以優雅地失敗。錯誤處理很重要。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/435702.html
標籤:拉拉维尔 laravel-5 雄辩 laravel-7 laravel-6
上一篇:使Web服務器運行腳本
