views:

163

answers:

4

I am trying to track down an issue with a cURL call in PHP. It works fine in our test environment, but not in our production environment. When I try to execute the cURL function, it just hangs and never ever responds. I have tried making a cURL connection from the command line and the same thing happens.

I'm wondering if cURL logs what is happening somewhere, because I can't figure out what is happening during the time the command is churning and churning. Does anyone know if there is a log that tracks what is happening there?

I think it is connectivity issues, but our IT guy insists I should be able to access it without a problem. Any ideas? I'm running CentOS and PHP 5.1.

Updates: Using verbose mode, I've gotten an error 28 "Connect() Timed Out". I tried extending the timeout to 100 seconds, and limiting the max-redirs to 5, no change. I tried pinging the box, and also got a timeout. So I'm going to present this back to IT and see if they will look at it again. Thanks for all the help, hopefully I'll be back in a half-hour with news that it was their problem.

Update 2: Turns out my box was resolving the server name with the external IP address. When IT gave me the internal IP address and I replaced it in the cURL call, everything worked great. Thanks for all the help everybody.

+1  A: 

In your php, you can set the CURLOPT_VERBOSE variable:

curl_setopt($curl, CURLOPT_VERBOSE, TRUE);

This then logs to STDERR, or to the file specified using CURLOPT_STDERR:

curl_setopt($curl, CURLOPT_STDERR, './path/to/file.log');

From the command line, you can use the following switches:

  • --verbose to report more info to the command line
  • --trace <file> or --trace-ascii <file> to trace to a file

You can use --trace-time to prepend time stamps to verbose/file outputs

adam
OK, that gave my a little more information, but not much. It just says:* About to connect() to [name of server] port 443* Trying [IP address of server]...Then it just hangs. Seems to me like a connectivity issue. Any other thoughts? I'm trying Pekka's answer right now.
SenorPuerco
Added some command line details. Have you tried setting a higher time limit to see if it ever returns? Use `set_time_limit(600)` to set to 10 mins
adam
Can you ping the ip address? Sounds like a network/firewall issue. If you can't, you can send it straight back to your IT guys and tell them to sort it!
adam
@Senor When I see port 443, it could indeed be an untrusted certificate issue. Can you try port 80 just for laughs?
Pekka
+1  A: 

If at all possible, try sudo ing as the user PHP runs under (possibly the one Apache runs under).

The curl problem could have various reasons that require a user input, for example an untrusted certificate that is stored in the trusted certificates cache of the root user, but not the PHP one. In that case, the command would be waiting for an input that never happens.

Update: This applies only if you run curl externally using exec - maybe it doesn't apply.

Pekka
I am using the PHP functions, so I guess it doesn't apply. Good thing to keep in mind, however.
SenorPuerco
A: 

You can also use curl_getinfo() to get information about your specific transfer.

http://in.php.net/manual/en/function.curl-getinfo.php

Ramesh Tabarna
Unless I'm wrong, this only is useful if a connection is made, right?
SenorPuerco
A: 

Have you tried setting CURLOPT_MAXREDIRS? I've found that sometimes there will be an 'infinite' redirect loop for some websites that a normal browser user doesn't see.

mgroves
Good thought, but it didn't change anything. Still just timed out.
SenorPuerco