如何处理致命错误:cURL错误7:无法连接到xxxx端口443 [英] How to handle Fatal error: cURL error 7: Failed to connect to xxxx port 443

查看:15634
本文介绍了如何处理致命错误:cURL错误7:无法连接到xxxx端口443的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本连接到第三方API。它是,应该是一个不间断的循环24/7(我使用睡眠在结束,然后重新启动循环)。

I have a script that connects to a third party API. It is and should be running on a non-stop loop 24/7 (I use a sleep at the end before restarting the loop).

问题是,有时第三方API被延迟或连接只会丢失与此错误:

The problem is that sometimes the third party API gets ddosed or the connection simply drops with this error:


致命错误:未捕获的异常
'GuzzleHttp \Ring \Exception\ConnectException,并显示消息cURL错误
7:无法连接到xxx.com端口443

Fatal error: Uncaught exception 'GuzzleHttp\Ring\Exception\ConnectException' with message 'cURL error 7: Failed to connect to xxx.com port 443

是否有任何方法来打破这个致命错误,以确保代码重新启动并继续,如果可以进行操作或必须手动重新启动每次我得到这个错误?

Is there any way to "break" on this fatal error to ensure the code is restarted and proceed if the action can be made or must I manually restart each time I get this error?

推荐答案

Michael的 评论


它看起来像你只能捕捉GuzzleHttp \Ring\Exception\ConnectException异常

it looks like you can just catch the GuzzleHttp\Ring\Exception\ConnectException exception

像这样:

use GuzzleHttp\Ring\Exception\ConnectException;

try {
    // the code which throws the error
} catch( ConnectException $ex ) {
    switch ( $ex->getMessage() ) {
        case '7': // to be verified
            // handle your exception in the way you want,
            // maybe with a graceful fallback
            break;
    }
}

它会出现guzzle的ConnectException 扩展 一些 ,最终扩展了php的异常,以便您可以安全地使用getCode()方法,允许您捕获一个标识符,您可以根据自己的需要做出相应的反应。

it appears guzzle's ConnectException extends some classes and ultimately extends php's Exception so you can safely use the getCode() method, allowing you to catch an identifier on which you can react accordingly to your needs.

这篇关于如何处理致命错误:cURL错误7:无法连接到xxxx端口443的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆