捕获PHP请求库中的curl错误

捕获PHP请求库中的curl错误,php,curl,Php,Curl,我正在使用https://github.com/rmccue/Requests 我使用随机代理发出请求有时代理会工作有时会失败:出现不同的错误: Uncaught异常“Requests\u exception”并显示消息“cURL error 28:connect()超时!” 我的问题是:如何捕捉这个CURL错误,并在循环中尝试另一个代理 我尝试了var\u dump($request->status\u code)它输出200个无规则的成功或失败 include('../library/Re

我正在使用
https://github.com/rmccue/Requests

我使用随机代理发出请求有时代理会工作有时会失败:出现不同的错误:
Uncaught异常“Requests\u exception”并显示消息“cURL error 28:connect()超时!”
我的问题是:如何捕捉这个CURL错误,并在循环中尝试另一个代理

我尝试了
var\u dump($request->status\u code)它输出200个无规则的成功或失败

include('../library/Requests.php');

// Next, make sure Requests can load internal classes
Requests::register_autoloader();

// Now let's make a request via a proxy.
$options = array(
    'proxy' => '$randomProxyIP:$randomProxyPort')
);
$request = Requests::get('http://httpbin.org/ip', array(), $options );


var_dump($request->status_code); 
在这里,你可以发现很多例外。另外,您的消息意味着您需要捕获异常
请求\u exception
。所有这些都是来自
请求_Exception
()的子类,因此基本上您应该:

try {
    $request = Requests::get('http://httpbin.org/ip', array(), $options );
} catch (Requests_Exception $e) {
    //something goes wrong
}
在这里,你可以发现很多例外。另外,您的消息意味着您需要捕获异常
请求\u exception
。所有这些都是来自
请求_Exception
()的子类,因此基本上您应该:

try {
    $request = Requests::get('http://httpbin.org/ip', array(), $options );
} catch (Requests_Exception $e) {
    //something goes wrong
}
在这里,你可以发现很多例外。另外,您的消息意味着您需要捕获异常
请求\u exception
。所有这些都是来自
请求_Exception
()的子类,因此基本上您应该:

try {
    $request = Requests::get('http://httpbin.org/ip', array(), $options );
} catch (Requests_Exception $e) {
    //something goes wrong
}
在这里,你可以发现很多例外。另外,您的消息意味着您需要捕获异常
请求\u exception
。所有这些都是来自
请求_Exception
()的子类,因此基本上您应该:

try {
    $request = Requests::get('http://httpbin.org/ip', array(), $options );
} catch (Requests_Exception $e) {
    //something goes wrong
}