I am using curl to connect to online Business Central (BC) web API, via OData. On postman, it takes a max of 1.9 seconds, but takes between 40 to 90 seconds on local server.
Any idea on how I can best improve this?
Here’s a sample of one of my curls – I have placed them in classes and passing the link, access token, and post fields (for POST to BC tables) via the class methods.
`
<?php
class employeeData
{
public function employee_meta_data($url,$access_token){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
CURLOPT_SSL_VERIFYPEER => false, //disable SSL certificate verification
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$access_token.'',
'Connection: keep-alive'
),
));
$response = curl_exec($curl);
if($response == FALSE)
{
//die("Web API Failed: ".curl_error($curl));
}else
{
$response_http_code = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
if($response_http_code >= 200 && $response_http_code <= 202){
$msg = json_decode($response);
}else
{
$msg = "error";
}
return $msg;
}
}
}
$employeeMetaData = new employeeData();
?>
I have gone through the previous recommended answers on this and other platforms, such as changing the http version to CURL_HTTP_VERSION_2TLS. Also, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 seems to work miracles for others but fails on to do the same on my side. Encoding is also enabled, but no changes still.
My internet speed (both home wifi and for the organisation) is fast and stable