简体   繁体   English

检查“连接超时”

[英]Check for a 'Connection timed out'

There's some trick i can do to check if the $cake_email->send() get Connection timed out ?For example: if I get a Connection Timed Out, i use a especific setFlash warning the user about the time out and redirect him to somewhere. 我可以采取一些技巧来检查 $ cake_email-> send()是否获得连接超时?例如:如果我获得连接超时,我将使用especific setFlash来警告用户有关超时并将其重定向到某个地方。

In my case, the email is something optional , if it sends: nice! 就我而言,电子邮件是可选的 ,如果它发送:很好! If it don't: no problem, just need to let the user know this 如果没有:没问题,只需要让用户知道

Actualy I'm using IF to check if it get some error, but this didn't catch the time out error 实际上,我正在使用IF来检查它是否出现一些错误,但这并没有捕获超时错误

$cake_email = new CakeEmail('gmail');
$cake_email->emailFormat('html');
$cake_email->to($dados['Requisitante']['email']);
$cake_email->template('atualizacaoRequisicao', 'default');
$cake_email->subject('ATUALIZAÇÃO DE REQUISICÃO');
$cake_email->viewVars(array('dados' => $dados));
if($cake_email->send()){
    $this->setFlash('A requisição foi salva e o email notificando a alteração foi enviado para '.$dados['Requisitante']['email'], 'flash_success');
} else {
    $this->setFlash('A requisição foi alterada, porém o email nao foi enviado', 'flash_info');
}

STLMikey 's comment (try/catch) solved my problem! STLMikey的评论(try / catch)解决了我的问题! Much more simple than I expected 比我预期的简单得多

I'll just let my actual code here in case of helping someone else with the same problem. 为了帮助其他有同样问题的人,我将在此处输入我的实际代码。

try {
    if($cake_email->send()){
        $this->setFlash('A requisição foi salva e o email notificando a alteração foi enviado para '.$dados['Requisitante']['email'], 'flash_success');
    } else{
        $this->setFlash('A requisição foi alterada, porém o email nao foi enviado', 'flash_info');
    }
} catch(Exception $ex){
    $this->setFlash('A requisição foi alterada, porém o email não foi enviado ('.$ex->getMessage().')<br>Você pode atualizar a requisição novamente para tentar reenviar o email', 'flash_info');
    return $this->redirect(array('action' => 'edit', $dados['Requisicao']['id']));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与mysql的连接超时 - Connection to mysql timed out AsyncTask上的连接超时 - Connection timed out on AsyncTask PHPMailer连接超时 - PHPMailer connection timed out AMQP - 连接超时 - AMQP - connection timed out Google SMTP连接超时 - Google SMTP connection timed out 连接超时-Db-Codeigniter - Connection Timed Out - Db - Codeigniter iframe 横幅: <!--? if connection timed out then</div--><div id="text_translate"><p> 在我的站点中,我使用 iframe 来显示来自其他站点的横幅。 问题是,其他站点的连接很少有问题。 现在偏离了那个“不那么频繁”的时间,空帧会出现,这不好。 我想要的是某种 php if..else 条件语句,可以将其重定向到其他横幅。 也许(逻辑上)它会是这样的:</p><pre> &lt;?php $iframe = the iframe url; $banner = the local banner url; if ($iframe connection timed out) {$banner;}?&gt;</pre><p> 我是一个 100% 的菜鸟,所以请帮助 p</p></div> - iframe banner: <? if connection timed out then 在类扩展上连接超时 - Connection timed out On Class Extend 如果连接超时则重定向 - Redirect if connection has timed out 通过数据库连接获取连接超时 - Getting connection timed out with DB connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM