TIPS & TRICKS

The Splunk SDK for PHP reaches Beta

The Splunk Software Development Kit (SDK) for PHP, which contains code, documentation and examples designed to help PHP developers programmatically interact with the Splunk engine and quickly build applications on Splunk, is now in Beta. The most significant changes with the Splunk SDK for PHP between Preview and Beta involve added support for the Splunk_Service class. The Splunk_Service class is the primary entry point for the client library. Developers can construct an instance of the Splunk_Service class and provide any arguments that are required to connect to an available Splunk server. Once the Splunk_Service instance is created, developers call the login method to provide login credentials. Once connected, developers can easily and efficiently work with various entities on the server, such as saved searches and search jobs.

The following shows an example of how to create a Splunk_Service instance and connect to Splunk:


// Import Splunk.php
require_once 'Splunk.php';

// Create an instance of Splunk_Service to connect to a Splunk server
$service = new Splunk_Service(array(
'host' => 'localhost',
'port' => '8089',
'username' => 'admin',
'password' => 'changeme',
));
$service->login();

The Beta of the Splunk SDK for PHP also includes the following helper methods to the Service class:


 search: $job = $service->search($searchExpression);

oneshotSearch: $resultsXmlString = $service->oneshotSearch($searchExpression);

The Splunk SDK for PHP is available for FREE, so if you’ve been curious about working with the SDKs and you know PHP, now is a great time to check it out.  Get started!

----------------------------------------------------
Thanks!
Jon Rooney

Splunk
Posted by

Splunk

Join the Discussion