cURL / Mailing Lists / curl-library / Single Mail

curl-library

Intermittent "couldn't connect to server" Message

From: Tim Gustafson <tgustafson_at_trustedid.com>
Date: Mon, 13 Aug 2007 11:49:13 -0700

Hello!

I am using libcurl in the context of a mySQL UDF. Here's the code I've got
so far:

curlHandle = curl_easy_init();
curl_easy_setopt(curlHandle, CURLOPT_URL, URL);
curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWrite);
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, r);
curl_easy_setopt(curlHandle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curlHandle, CURLOPT_TIMEOUT, 30);
curl_easy_setopt(curlHandle, CURLOPT_LOCALPORT, 1024);
curl_easy_setopt(curlHandle, CURLOPT_LOCALPORTRANGE, 100);
curl_easy_setopt(curlHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0);
curl_easy_setopt(curlHandle, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curlHandle, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curlHandle, CURLOPT_FORBID_REUSE, 1);
curl_easy_setopt(curlHandle, CURLOPT_CONNECTTIMEOUT, 0);
curlCode = curl_easy_perform(curlHandle);
curl_easy_cleanup(curlHandle);

About 70% of the time, this all works beautifully. However, about 30% of
the time, I'm getting the following error message:

couldn't connect to server

There doesn't seem to be any rhyme or reason to this error message. I'm
fairly sure that the server I'm connecting to isn't failing 30% of it's
requests. When I test the same URL in my web browser, it works every time.
I'm wondering if maybe it has something to do with mySQL calling curl from
within a thread. How can I make the block of code above thread-friendly to
prevent the error from happening?

Thanks in advance for any help!

Tim
Received on 2007-08-13