PHP curl not returning data in all cases PHP curl not returning data in all cases curl curl

PHP curl not returning data in all cases


If you need response in $res

$res = curl_exec($ch);

You must set

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

Otherwise curl sends it to stdout


If you use Apache HTTPd try to restart it.
It solved my problem with an empty response in cURL requests.


For some reason the FETCH data is returned as header data, which by default pipes to stderr. You can capture it via the CURLOPT_HEADERFUNCTION callback. For example, to store it to a file, something like this:

    $fileHandle = tmpfile();    curl_setopt($this->ch, CURLOPT_HEADERFUNCTION,      function ($ch, $str) use ($fileHandle) {        fwrite($fileHandle, $str);        return strlen($str);      }    );