forked from christophe-lejeune/cassandre_2_php
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp.php
More file actions
20 lines (17 loc) · 686 Bytes
/
http.php
File metadata and controls
20 lines (17 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
define('BASE_URL', 'http://127.0.0.1:5984/cassandre/_design/cassandre/_view/');
function get($url) {
$headers = array('Accept: application/json');
$ch = curl_init(BASE_URL.$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30 );
$response = curl_exec( $ch );
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if(substr($status_code, 0, 1) != "2")
throw new Exception(BASE_URL.$url, $status_code);
return (strlen($response) > 0) ? json_decode($response) : true;
}
?>