4
Good afternoon guys, appeared a problem to solve on a site, something that had not yet moved.
The following is, on the page I have a form where the person can register. When making the registration, I send an email to her confirming this registration.
Now, we will start using SMS also, ie the person sign up, receive an email and a SMS confirming (company rules). But my manager wants the SMS to arrive after about 5 min that the person made the registration on the site.
Right now, I’m sending the text right away, but he wants it done the way he said it.
Can someone help me ?
Note: I submit the form on the same page that I do.
function sendSms(){
$nome = explode(" ",$_POST['txtNome']); // pega o nome via post , e joga cada palavra em um array
$corrigir = array(' ','-','(',')','{','}','/',' ');// array que elimina caractres do telefone ,deixando somente os numeros
$corpoSMS = 'SKY HDTV:Caro(a).'$nome[0].',informamos que seus dados foram enviados para nosso dpt de cadastros.Dentro de 24h,entraremos em contato com maiores informacoes'; //monta o corpo do sms , mantendo o limite de 160 caracteres.
$tel = str_replace($corrir,'',$_POST['txtCel']);
$msg = str_replace(' ','+',$corpoSMS);
//código da página enviapost.php
$dados_post = array(
"" => $tel,
"?message=" => $msg,
);
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'header' => array(
'Content-Type: application/x-www-form-urlencoded'),
'content' => http_build_query($dados_post)
)
)
);
$host = 'https://meuservidordesms.com.br/'.$tel.'?message='.$msg;
$result = file_get_contents($host,false,$context);
if(preg_match("/SUCESSO/", $result)){
echo ' <script type="text/javascript">
alert("SMS enviado com sucesso!");
</script>';
} else {
echo '<script type="text/javascript">alert("Erro enviar o SMS.<br>");</script>';
}
}// FUNCAO QUE ENVIA O SMS AO CLIENTE.
Have you ever tested the impact it would have on getting these text messages stacked? Doesn’t it create a bottleneck in the system? There would be some problem if you saved it in file or database and then ran a task every time you read this data and sent it. Example of a scheduled task? Roughly as if using an Observer?
– Israel Zebulon
Good evening, Voce would have some example or link showing how it could do ? Grateful
– Henrique Felix
A thread that queries in the database every 5 seconds which are the next SMS to send, I never used Thread in PHP, but in other languages like Delphi and Java. The following is documentation: http://php.net/manual/en/class.thread.php.
– Giancarlo Abel Giulian
This might help you http://www.phpclasses.org/package/9047-PHP-Execute-asynchronous-tasks-in-the-background.html
– Leandro Amorim
You can use a queue service like: Amazon SQS, Beanstalkd, Ironmq, ...
– vmartins