在Curl中请求cUrl

I have action something like this

public function coordinatAction()
{
    $curl = curl_init('https://maps.googleapis.com/maps/api/geocode/json?latlng=30.0000000000,40.0000000000');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $aParams);

    //Sending request
    $result = curl_exec($curl);
    if (false === $result) {
        $sResult = curl_error($curl);
    };
    curl_close($curl);

    return $result;
}

And have unit test for this action:

public function coordinatActionTest()
{
    $curl = curl_init();
    $params = [/** Some Params */]
    curl_setopt($curl, CURLOPT_URL, 'http://mysite.local/coordinate'); //path to my action
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $params);

    $response = curl_exec($curl);
    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    curl_close($curl);

    $this->assertEquals(200, $httpCode, "Wrong HTTP Response Code");
}

When I execute test I get request "curl in curl" (curl in test call curl in action), but second curl is failed by time out after 5 minutes. If I call just one curl in action it everything ok, but duble curl is timed out. Could any explain why it happens

First make sure that the url is accessible using browser. http://mysite.local/coordinate. You can do it using curl command too to verfiy the link. For example:

curl -XPOST YOUR_URL -d _YOUR_PARAMS

Secondly, it can happen that your server doesn't accept any request without a proper user-agent string. I'ld recommend you to use CURLOPT_USERAGENT option with your curl test (with any browser like Opera or Mozila).

Finally, check your server's httpd.conf file and see what are the other parameters mandatory for an incoming request.