CURLOPT_PUT vs CURLOPT_POSTFIELDS

Viewed 10237

When I sent the PUT request API via curl to the REST, I found strange behavior. If you set the parameter curl_setopt($curl, CURLOPT_PUT, true), then queries, in which CURLOPT_POSTFIELDS is not empty, then the query execution lasts 1.5 minutes (as if it depends on some timeout). And if the same request is sent with the parameter curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"), then the query execution lasts about 1 second, as it should be. Can someone explain the fundamental difference between these parameters?

Example code:

$data = http_build_query(array("enable"=> 1));

if( $curl = curl_init() ) {
    curl_setopt($curl, CURLOPT_URL, BASE_URL .'users/2');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);    
    curl_setopt($curl, CURLOPT_PUT, true); // execution time 1.5 min
    //curl_setopt ($ curl, CURLOPT_CUSTOMREQUEST, "PUT"); - execution time 1 sec
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $out = json_decode(curl_exec($curl));
    curl_close($curl);      
}
1 Answers
Related