I'm developing a script where I'm using PHP and cURL to fetch data from a REST web service.
My problem is that curl_exec often times out in the PHP script, but when I try the same request from the command line cURL client I get an instant answer.
It seems like the PHP cURL somehow caches this timeout for some time and then suddenly decides that it's going to fetch the data I need. Multiple reloads produces the same result: timeout. And after a few minutes everything works fine. The command line cURL client has been getting data all the time.
What can be wrong?