<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[很少遇到]How to catch curl errors in PHP,怎么捕获PHP里的Curl出现的超时发生的异常错误？]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Thu, 13 Jun 2013 01:31:44 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：用try catch去捕获php的curl错误，是不行的，<br/>The PHP cURL functions do not throw exceptions, so there will never be anything to catch. You&#039;ll just have to check the return value for a boolean false.<br/>As to why the cURL timeout does not seem to be occurring after 30 seconds, I&#039;m not sure. <br/><br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
&nbsp;&nbsp;&nbsp;&nbsp;$url=&quot;12122222.com&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$agents = &quot;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1&quot;;
&nbsp;&nbsp;$ch = curl_init();
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_HEADER, 0);
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_USERAGENT, $agents);
&nbsp;&nbsp;curl_setopt($ch, CURLOPT_URL, $url);
&nbsp;&nbsp;$curlResp = curl_exec($ch);
&nbsp;&nbsp;&nbsp;&nbsp;if(curl_errno($ch))
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;error:&#039; . curl_error($ch);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;/*
&nbsp;&nbsp;if ($curlResp === FALSE) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception(&quot;Curl Has Some Wrong ,Please Check It。&quot;);
&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;curl_close($ch);

</textarea><br/>上面代码返回：<br/>error:Could not resolve host: 12122222.com; Host not found<br/><br/>打开注释代码返回：<br/>Fatal error: Uncaught exception &#039;Exception&#039; with message &#039;Curl Has Some Wrong ,Please Check It。&#039; in D:&#92;wamp&#92;www&#92;curl_try_catch.php on line 14<br/>Exception: Curl Has Some Wrong ,Please Check It。 in D:&#92;wamp&#92;www&#92;curl_try_catch.php on line 14<br/>---<br/>返回一些状态码，URl如下：curl.haxx.se/libcurl/c/libcurl-errors.html<br/>再进行捕获。<br/>来自：<br/>http://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php<br/><br/>You can use the curl_error() function to know if there was some error, example:<br/><br/>if(curl_errno($c))<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;error:&#039; . curl_error($c);<br/>&#125;<br/>===================================================<br/><br/>I&#039;m trying to debug this cURL-operation. The var_dump() is returning bool(false)<br/>How can I make it exit the try in that case?<br/><textarea name="code" class="php" rows="15" cols="100">
function parse($url, $headonly = TRUE )&#123;
&nbsp;&nbsp;&nbsp;&nbsp;$agents = &#039;Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16&#039;;
&nbsp;&nbsp;&nbsp;&nbsp;try
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ch = curl_init();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_HEADER, 0);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_USERAGENT, $agents);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_URL, $url);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$curlResp = curl_exec($ch);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($ch);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var_dump($curlResp); //RETURNS bool(false)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$resp = str_replace(&quot;class=l&quot;,&quot;class=&#039;l&#039;&quot;,$curlResp);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $resp;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;catch( Exception $e)
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$strResponse = &quot;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$strErrorCode = $e-&gt;getCode();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$strErrorMessage = $e-&gt;getMessage();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print_r($arrCurlInfo, $strErrorCode, $strErrorMessage);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;//end catch
&#125;
</textarea><br/><br/>Why not try throwing an Exception when false is returned?<br/><br/><textarea name="code" class="php" rows="15" cols="100">
if ($curlResp === FALSE) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception(); 
&#125;
</textarea><br/><br/>Look here: php.net/manual/en/function.curl-exec.php; basically, false means the operation failed. <br/>Found it: echo curl_error($ch); &quot;Couldn&#039;t connect to host&quot; <br/><br/>http://stackoverflow.com/questions/7069822/curl-try-catch-problem<br/><br/><br/>群讨论：<br/>回忆未来-向东-Jàck(372647***)&nbsp;&nbsp;上午 10:49:40<br/>PHP try catch 能抓到Curl的timeout吗<br/>一周工作五天(243801***)&nbsp;&nbsp;上午 10:50:58<br/>不能<br/>回忆未来-向东-Jàck(372647***)&nbsp;&nbsp;上午 10:52:15<br/>常规处理办法是？<br/>三德子(277940***)&nbsp;&nbsp;上午 10:52:31<br/>curl没有抛异常 除非你去做个errorhandler<br/>回忆未来-向东-Jàck(372647***)&nbsp;&nbsp;上午 10:52:39<br/>前一段时间我写过博文，但没有根治：http://www.jackxiang.com/post/6445/<br/>errorhandler&nbsp;&nbsp;？<br/>有示例demo么。<br/>三德子(277940***)&nbsp;&nbsp;上午 10:53:02<br/>在errorhandler中 抛errorexception<br/>看手册 errorexception这一章<br/>回忆未来-向东-Jàck(372647***)&nbsp;&nbsp;上午 10:53:48<br/>嗯，超时捕获有code值没？<br/>三德子(277940***)&nbsp;&nbsp;上午 10:53:57<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) &#123;
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
&#125;
set_error_handler(&quot;exception_error_handler&quot;);

/* Trigger exception */
strpos();
?&gt;
</textarea><br/>一周工作五天(243801***)&nbsp;&nbsp;上午 10:55:41<br/>搞那么复杂干嘛&nbsp;&nbsp;直接把 超时时间设置长些不就ok了<br/><br/>----------------------------------------------------------------------------------------------<br/>强制用try catch作下实践如下：<br/><textarea name="code" class="php" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;public function testTimeOut()&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$user_mobile_gsidlogin_url = &quot;http://jackxiang.com/test/testMaxTimeUrl&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data = array();//Post Data
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$vericode = Remote::get($user_mobile_gsidlogin_url,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CURLOPT_USERAGENT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#039;Mozilla/5.0 (compatible; KoPHP v3.0 +http://kophp.com/)&#039;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CURLOPT_POST =&gt; TRUE,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CURLOPT_POSTFIELDS =&gt; http_build_query($data),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CURLOPT_CONNECTTIMEOUT =&gt; 5,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CURLOPT_TIMEOUT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; 5,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);//发送GET请求
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $vericode;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch (Exception $e)&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;Max Time Out...time out。&lt;hr&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&nbsp;$e-&gt;getmessage();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;public function testMaxTimeUrl()&#123;
&nbsp;&nbsp;&nbsp;&nbsp;sleep(10);
&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;10 sec pass!&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
</textarea><br/>访问：http://jackxiang.com/test/testTimeOut<br/>Max Time Out...time out。<br/>Error fetching remote http://jackxiang.com/test/testMaxTimeUrl [ status 0 ] <br/>Error fetching remote http://jackxiang.com/test/testMaxTimeUrl [ status 0 ] <br/>Operation timed out after 5007 milliseconds with 0 bytes received<br/>其实上述说明，不在curl里捕获，在外面一层也是能捕捉到的，只是错误的message提示是：Error：Operation timed out after 5007 milliseconds with 0 bytes received！<br/>________________________________________________________________________________________________<br/>在生产中的代码，用try catch实现的Remote:get，来自KO框架，作了下简单修改（有时Url为空，不知是谁调的，Add Time:2014/03/26）：<br/><textarea name="code" class="php" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;* @param&nbsp;&nbsp; string&nbsp;&nbsp; remote URL
&nbsp;&nbsp;&nbsp;&nbsp; * @param&nbsp;&nbsp; array&nbsp;&nbsp;&nbsp;&nbsp;curl options
&nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp;&nbsp;string
&nbsp;&nbsp;&nbsp;&nbsp; * @throws&nbsp;&nbsp;KoException
&nbsp;&nbsp;&nbsp;&nbsp; */
&nbsp;&nbsp;&nbsp;&nbsp;public static function get($url, array $options = NULL)
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($options === NULL) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Use default options
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$options = self::$default_options;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; else &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Add default options
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$options = $options + self::$default_options;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$log = Log::instance(__CLASS__)-&gt;attach(new Log_File(DATA_PATH . &#039;logs&#039;.DIRECTORY_SEPARATOR . date(&#039;Ymd&#039;).DIRECTORY_SEPARATOR, __CLASS__.&#039;-&#039; . date(&#039;Ymd&#039;) . &#039;.log&#039;));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The transfer must always be returned
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$options[CURLOPT_RETURNTRANSFER] = TRUE;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$response = false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Open a new remote connection
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$remote = curl_init($url);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(KO::$threshold &gt;= 3)&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ldata = array(&#039;uri&#039; =&gt; $url, &#039;options&#039; =&gt; $options);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$log-&gt;add(&#039;remote_log&#039;, $ldata);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Set connection options
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt_array($remote, $options);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (array_key_exists(CURLOPT_POST, $options)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($remote, CURLOPT_HTTPHEADER, array(&#039;Expect:&#039;));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get the response
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$response = curl_exec($remote);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get the response information
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$code = curl_getinfo($remote, CURLINFO_HTTP_CODE);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($code AND $code &lt; 200 OR $code &gt; 299) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error = $response;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; elseif ($response === FALSE) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error = curl_error($remote);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Close the connection
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($remote);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (isset($error)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data = array(&#039;:url&#039; =&gt; $url, &#039;:code&#039; =&gt; $code, &#039;:error&#039; =&gt; $error);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$log-&gt;add(&#039;remote-error&#039;, $data);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new KoException(&#039;Error fetching remote :url [ status :code ] :error&#039;, $data);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; catch (Exception $e) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (Ko::trace($trace) as $i =&gt; $step)&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($step[&#039;function&#039;] == &quot;Remote::get&quot;)&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$traceInfoStr = &quot;Remote::get called by: &quot;.$step[&#039;file&#039;].&quot; line:&quot;.$step[&#039;line&#039;].&quot; param:&quot;.var_export($step[&#039;args&#039;],TRUE);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data = array(&#039;:url&#039; =&gt; $url, &#039;:code&#039; =&gt; $code, &#039;:error&#039; =&gt; $e-&gt;getMessage(),&quot;:traceinfo&quot; =&gt; $traceInfoStr);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$log-&gt;add(&#039;remote-error&#039;, $data);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new KoException(&#039;Error fetching remote :url [ status :code ] :error&#039;, $data);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $response;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
</textarea>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [很少遇到]How to catch curl errors in PHP,怎么捕获PHP里的Curl出现的超时发生的异常错误？]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>