CURL hangs on request, waits for timeout

I am facing a problem that I cannot find a solution to anywhere. Worse, others don't have this problem, so I'm probably doing something very stupid.

Some background information. I am trying to create a proxy like page that redirects an AJAX request to another server. This will bypass the single domain policy. All I want this code to do is take the POST variables, post them to another page, and then return the results. It works, but for 1 thing: every time it waits for the timeout to continue. I put it on for 1 second, so it works fine now, but I would have preferred a quick response and correct timeout.

Here's my code:

// create a new cURL resource
$call = curl_init();

// set URL and other appropriate options
curl_setopt($call, CURLOPT_URL, $url);
curl_setopt($call, CURLOPT_POST, true);
curl_setopt($call, CURLOPT_POSTFIELDS, $params);
curl_setopt($call, CURLOPT_HEADER, false);
curl_setopt($call, CURLOPT_RETURNTRANSFER, true);
curl_setopt($call, CURLOPT_CONNECTTIMEOUT, 1);

// grab URL and pass it to the browser
$response = curl_exec($call);

// close cURL resource, and free up system resources

echo $response;


I tried to send the header "Connection: close" with it and several ways to make the target code specified in it (setting Content-length, flushing, die (), etc.). At this point I really don't know what's going on, what surprises me the most is that I can't find anyone with a similar problem.

Who can help me?


source to share

2 answers

This would make sense if the server wasn't actually making the request. This would be expected in a streaming or streaming service scenario. Are you sure the server is actually returning a complete and complete HTTP response for every request?



It looks like it is trying to connect, timeout and retry is working.

This fixed it for me:



I can connect to the command line via ipv6, so I don't know why it helps.



All Articles