Splunk API works on Postman but not on PHP

I have a CakePHP application where I’m calling 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_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_USERPWD => 'Basic ' . base64_encode("user:password"),
        CURLOPT_HTTPHEADER => array(
            'Authorization: Basic ' . base64_encode("user:password")

        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

        $response = curl_exec($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?

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Site Moderator
Site Moderator badge
July 6, 2022

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 executing php -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.


Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up