Splunk API works on Postman but not on PHP

Viewed 91

I have a CakePHP application where I'm calling 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?

0 Answers
Related