简体   繁体   中英

how to detect connection reset errors in PHP

So I've been using CURL to get some portions of remote images....but then depending on what I pass as the CURLOPT_HTTPHEADER it will sometimes return connection reset error instead of getting the image...

My question is...is there a way to accurately and reliably detect when such connection reset errors occur in PHP and more importantly to disregard that image fetch when that happens and move on with the script without the image fetch as if nothing has happened....

Also I'm using curl_multi_exec and curl_multi_getcontent since I'm parallelizing the process

I'm also calling the function imagecreatefromstring() and I found that the error probably has to do with imagecreatefromstring() since uncommenting that line ends all connection reset errors...

You can get more information on cURL errors by using curl_errno . See the first comment on that page for details.

curl_exec() returns a boolean FALSE if an error occurs, so

$result = curl_exec($handle);
if ($result === FALSE) {
   ... an error occured ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM