Postman vs PHP cURL response time

134 views Asked by At

I have an API call and it is taking 0.5 to 1 second in POSTMAN whereas the same API call taking 7 to 12 seconds with PHP cURL and its response time is totally abnormal. How should I increase this response time?

My code :

<?php

$curl = curl_init();

$voicefile = $argv[1];

$auth = $argv[2];

curl_setopt_array($curl, array(

  CURLOPT_URL => 'https://api.openai.com/v1/audio/transcriptions',

  CURLOPT_RETURNTRANSFER => true,

  CURLOPT_ENCODING => '',

  CURLOPT_MAXREDIRS => 10,

  CURLOPT_TIMEOUT => 30,

  CURLOPT_FOLLOWLOCATION => true,

  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

  CURLOPT_CUSTOMREQUEST => 'POST',

  CURLOPT_TCP_KEEPALIVE => 1,

  CURLOPT_TCP_KEEPIDLE => 2, // Time in seconds before sending keepalive probes

  CURLOPT_TCP_KEEPINTVL => 1, // Time in seconds between keepalive probes

  CURLOPT_SSL_VERIFYPEER => true,

 

  CURLOPT_POSTFIELDS => array('model' => 'whisper-1','file'=> new CURLFILE('/var/lib/asterisk/sounds/en/restaurant/'.$voicefile.'.wav')),

  CURLOPT_HTTPHEADER => array(

'Authorization: Bearer '.$auth ,

'cache-control: no-cache' // ,

  ),

));

echo "Seconds before API Call :". time()."\n";

$response = curl_exec($curl);

curl_close($curl);

echo $response;

echo "\n Seconds after API Call:" . time()."\n";

?>
0

There are 0 answers