Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $doc = ["abc"=>"testing"];
- $resp = json_decode(bulkUpdate($doc));
- var_dump($resp);
- function bulkUpdate($doc)
- {
- if(is_array($doc))
- {
- $root = new Stdclass();
- $root->docs = $doc;
- $doc = json_encode($root);
- $config = include("/home/app/config/db.php");
- $user = $config['user'];
- $pass = $config['pw'];
- $host = $config['host'];
- $db = $config['db'];
- $headers = array(
- 'Accept: application/json',
- 'Content-Type: application/json',
- 'Content-Length: '.strlen($doc),
- "Authorization: Basic ".base64_encode("$user:$pass"),
- );
- $contextOptions = array('http' =>
- array(
- 'method' => 'POST',
- 'header'=>$headers, $
- 'content' => $doc,
- 'timeout' => 60) $
- );
- $sslContext = stream_context_create($contextOptions);
- $url = "$host/$db/_bulk_docs";
- $send = file_get_contents($url, NULL, $sslContext);
- $ret = $send;
- }
- else
- {
- $ret = -1;
- }
- return $ret;
- }//end func
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement