[英]How to put a time interval for same task in php
我有一個短信應用程序,我想設置一個時間間隔,當用戶通過一個號碼發送短信時,他需要等待1個小時或任何在腳本中聲明如何執行的時間間隔?
<?php //FILE: sms_api.php
function sendSMS($number, $message) {
$url = "example"; // Set your frontlinesms or frontlinecloud webconnection url here
$secret = "secret"; // Set the secret here
$request = array(
'secret' => $secret,
'message' => $message,
'recipients' => array(array(
'type' => 'mobile',
'value' => $number
))
);
$req = json_encode($request);
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $req );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch);
return split(',',$result);
}
?>
<?php //FILE: index.php
include 'sms_api.php';
$number = '+123456789';
$text = 'Hi There, how are you?';
$sms_api_result = sendSMS($number, $text);
// Check if SMS was sent. The $sms_api_result boolean indicates whether the API call was successful.
// You can replace the code below with custom handling logic
if ($sms_api_result[0] == 'OK') {
// Ok, SMS received by the API
echo 'The SMS was sent.';
}
else {
// Failure, SMS was not sent
// In this example we display the response to identify the error
print_r($sms_api_result);
}
?>
您可以將記錄存儲在數據庫表中。 並且在發送短信時檢查手機號碼。 如果他在上一個小時發送了短信,則可以將他重定向到高級頁面或其他地方。 睡眠不起作用睡眠只會增加網站加載所需的時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.