Skip to content
Snippets Groups Projects
Commit c0cdbe90 authored by Alvaro Graves's avatar Alvaro Graves
Browse files

switched from file_get_contents to curl in query function

parent 78ea4b19
No related branches found
No related tags found
No related merge requests found
......@@ -9,27 +9,38 @@ class Endpoint{
$this->params = $params;
}
public function query($q, $output = 'json'){
global $conf;
$auxoutput = $this->params['output'];
if($output != null){
$this->params['output'] = $output;
}
$context = stream_context_create(array(
'http' => array('header'=>'Connection: close')));
$params = $this->params;
$params['query'] = $q;
$url = $this->sparqlUrl.'?'.http_build_query($params, '', '&');
$aux = file_get_contents($url, false,$context);
$this->params['output'] = $auxoutput;
if(preg_match("/select/i", $q)){
return json_decode($aux, true);
}
if(preg_match("/describe/i", $q)){
return $aux;
}
public function query($q, $output = 'json'){
global $conf;
$auxoutput = $this->params['output'];
$accept = 'application/sparql-results+json';
if($output != null){
$this->params['output'] = $output;
}
if($output == 'xml'){
$accept = 'application/sparql-results+xml';
}
$c = curl_init();
$context = array();
$context[0] = 'Connection: close';
$context[1] = 'Accept: '.$accept;
$params = $this->params;
$params['query'] = $q;
$url = $this->sparqlUrl.'?'.http_build_query($params, '', '&');
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_HTTPHEADER, $context);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$aux = curl_exec($c); // execute the curl command
curl_close($c);
$this->params['output'] = $auxoutput;
if(preg_match("/select/i", $q)){
return json_decode($aux, true);
}
if(preg_match("/describe/i", $q)){
return $aux;
}
}
public function queryPost($q){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment