In what scenarios does PHP's cURL functionality automatically set "Expect: 100-continue" and how can this impact data transmission?

When using PHP's cURL functionality to make HTTP requests, the "Expect: 100-continue" header is automatically set in certain scenarios, such as when sending large amounts of data. This header tells the server to expect the client to send the body of the request after receiving a 100 Continue response. However, some servers may not handle this header correctly, leading to delays or issues in data transmission. To prevent cURL from automatically setting the "Expect: 100-continue" header, you can explicitly disable it by setting the CURLOPT_HTTPHEADER option to an empty array.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

// Disable "Expect: 100-continue" header
curl_setopt($ch, CURLOPT_HTTPHEADER, array());

$response = curl_exec($ch);

if ($response === false) {
    echo 'cURL error: ' . curl_error($ch);
}

curl_close($ch);