Curl http_code of 000

curlhttp

I have a shell script that I use to monitor loading times and response codes on my live server cluster. It runs a total of 250 iterations every 5 minutes, distributed across 10 servers and 6 sites. It uses curl with the -w flag to return pertinent information which is then parsed by my shell script:

curl -svw 'monitor_load_times %{time_total} %{http_code}' -b 'server=$server' -m 15 -o /dev/null $url 2>&1

This information is then parsed by a graphing script that can display a number of different responses. However, curl will occasionally return a response code of "000". When this happens, it seems to happen multiple times at once despite being distributed over many iterations:

Error code graph

What I'm trying to work out is if this is a client-side issue that's skewing my results or if it's actually indicative of a server-side problem affecting my entire cluster. Does 000 mean that the connection was dropped? Database entries corresponding to curl iterations with that response code return "0.000" for the time_total value. All of the search results I've found for curl returning a code of 000 are related to HTTPS being unsupported, but all of my test URLs are HTTP.

(The spike in 500 errors is a completely unrelated issue that affected my servers last night.)

Best Answer

The response 000 indicates that cURL failed to execute for some reason. In such a case, you should test for cURL exit code rather than making assumptions. See the "Exit Codes" section of the curl manpage for a full list of exit codes and their meanings.

Failed DNS resolution (6)

$ curl -w "%{http_code}\n" http://example.invalid/ ; echo "Exit code: $?"
000
curl: (6) Could not resolve host: example.invalid
Exit code: 6

(As answered by ILIV)

Connection refused (7)

$ curl -w "%{http_code}\n" http://localhost:81/ ; echo "Exit code: $?"
000
curl: (7) Failed to connect to localhost port 81: Connection refused
Exit code: 7

Connection timed out (28)

$ curl -w "%{http_code}\n" -m 5 http://10.255.255.1/ ; echo "Exit code: $?"
000
curl: (28) Connection timed out after 5001 milliseconds
Exit code: 28

(As answered by Arun)

Server actually returns 000 for some reason (0)

Start a fake server:

$ nc -l -p 65535 & <<EOF
> HTTP/1.1 000 Fake Status Code
> Content-Length: 0
> Connection: close
>
> EOF

Client request:

$ curl -w "%{http_code}\n" http://localhost:65535/ ; echo "Exit code: $?"
000
Exit code: 0

No idea why this would happen in the real world, but hey. If cURL doesn't get a valid status code at all, it assumes 200.

Related Question