我有一些PHP代码,借此将数据发布到API并获得一些响应数据。当用户付款时,API的响应状态应更改。我试图延迟执行PHP代码并等待15秒钟,然后才能从API中获得付款状态,该状态无法按预期工作。。由于使用Laravel 5.4,我不知道如何在PHP或Laravel Queue中做到这一点
〜请协助?
$data = array(
'payment_reference' => $checkID,
'payment_type' => $type
);
//Post request to an API and get the status and store in a variable
$paySt = $this->global_Curl($data, 'api/payment/status')->data;
sleep(15);
//Second call to the API after sleep to check if status has changed
$payStat = $this->global_Curl($data, 'api/payment/status')->data;
if($payStat->status === '1'){
return 'true';
}
答案 0 :(得分:0)
sleep()
函数用于延迟当前执行
检查链接
https://www.w3schools.com/php/showphp.asp?filename=demo_func_misc_sleep
对于您而言,您需要在4-5秒的延迟后再次调用付款api
例如:
#Payment process hit code
#sleep(4); //delay/wait for 4 second
#Again run code to check the payment status.