How can I use a PHP script to index URLs or documents?

Once you download the PHP examples from our Downloads page (, you will need to update the following fields in your PHP script to ensure you can index URLs/documents to SearchBlox:

* SearchBlox installation path (http://localhost:8080/searchblox/api/rest/add)
* SearchBlox API key
* SearchBlox custom collection name (Please create a custom collection once you install SearchBlox.)

Refer to the Developer page for parameters that can be passed through the XML message:

Here is a sample PHP script that can be used to index URLs or documents (filesystem can be specified only when using the same server as SearchBlox):

// Example code adding a document using rest API
function searchblox_index() {
$xml_input='<?xml version="1.0" encoding="utf-8"?>
&lt;searchblox apikey="C1E6FCF058DC2D79F72C9CDF30B5B1AF">
&lt;document colname="ht_sumod" location="">
&lt;url> </url&gt;
&lt;title boost="1"> My custum collection</title&gt;
&lt;keywords boost="1">keywords</keywords&gt;
echo $xml_input;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array('Content-Type: text/xml'));
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS,trim($xml_input));
$body = curl_exec($ch);
echo 'searchblox_curl_warning';
$xml = simplexml_load_string($body);
global $statuscode;
$statuscode = (string) $xml->statuscode;
if (intval($statuscode)>=100 AND intval($statuscode)<=701)
echo 'searchblox_xml_warning';
if ( intval($statuscode) == 100 )
$error_count = 0; // After first succesful connection, lets reset error counter
//else $error_count++; // Skip if document cannot be indexed
elseif ( $statuscode <> '' )
echo 'searchblox_unknown_reply';
//$error_count++; // Skip if document cannot be indexed
if ( isset($_POST['sb_index'])) searchblox_index( );
&lt;div style="width:25%; float:left;"&gt;
&lt;form name="sb_index_form" method="post" action=""&gt;
&lt;input type="submit" id="sb_index" name="sb_index" value="Index Document" /&gt;

Have more questions? Submit a request