I have a CakePHP application where I’m calling https://hkrtrainings.com/splunk-api to make a search and obtain its results. It works as a charm when I try it on Postman, but when run by my server it doesn’t return results every time. In fact, when I call the API constantly inside a while loop, it does tend to bring results, although sometimes it could take more 2 minutes to return something.
I’m calling Splunk this way:
$querying = array( “search” => “search index=api_sandbox OR index=api_prod token=” .$token, “output_mode” => “raw” ); $querying = http_build_query($data); try{ $curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://mysplunk:8089/servicesNS/user/environment/search/jobs/export?' . $querying,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER, false,
CURLOPT_USERPWD => 'Basic ' . base64_encode("user:password"),
CURLOPT_HTTPHEADER => array(
'Authorization: Basic ' . base64_encode("user:password")
),
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}catch (\Throwable $th) {
Log::error("callApi ERR: " . $th->getMessage());
debug("Error: " . $th->getMessage());
return false;
}
The API call is run inside a CakePHP Shell Task, and for the record when executed the Shell Task through console command (php bin/cake.php Queue.Queue runworker) the API does return results without empty results.
Why this strange behavior could be occurring?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hello there,
Can you verify if the PHP version used in the console is the same that the application is using?
This can be verified using
phpinfo
file and when executingphp -v
inside the shell console.Additionally, if the CakePHP app has other dependencies like custom modules you can verify that they’re all enabled using the
phpinfo
function.Regards