Skip to content

Instantly share code, notes, and snippets.

@prateeksachan
Created September 30, 2013 19:21
Show Gist options
  • Save prateeksachan/6768755 to your computer and use it in GitHub Desktop.
Save prateeksachan/6768755 to your computer and use it in GitHub Desktop.
<?php
require_once( 'bootstrap.php' );//solr connection settings
//This is the running solr server at 127.0.0.1:8983 as defined in bootstrap.php
$options = array( 'hostname' => SOLR_SERVER_HOSTNAME );
// Try to connect to the named server, port, and url
$client = new SolrClient($options);
if (!$client->ping()) {
exit ('Solr service not responding.');
}
$data = 'myfile=@a.pdf';
$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_URL, "http://localhost:8983/solr/update/extract?literal.id=doc1&commit=true&literal.module=forum&literal.type=1&literal.courseid=1");
curl_setopt($tuCurl, CURLOPT_POST, 1);
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, array('myfile'=>"@a.pdf"));
//print_r($tuCurl);
$tuData = curl_exec($tuCurl);
if(!curl_errno($tuCurl)){
$info = curl_getinfo($tuCurl);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
} else {
echo 'Curl error: ' . curl_error($tuCurl);
}
curl_close($tuCurl);
echo $tuData;
$client->commit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment