Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2.  
  3. $doc = ["abc"=>"testing"];
  4.  
  5. $resp = json_decode(bulkUpdate($doc));
  6.  
  7. var_dump($resp);
  8.  
  9. function bulkUpdate($doc)
  10.         {
  11.                 if(is_array($doc))
  12.                 {
  13.                         $root = new Stdclass();
  14.                         $root->docs = $doc;
  15.                         $doc = json_encode($root);
  16.  
  17.                         $config = include("/home/app/config/db.php");
  18.  
  19.                         $user = $config['user'];
  20.                         $pass = $config['pw'];
  21.                         $host = $config['host'];
  22.                         $db = $config['db'];
  23.  
  24.                         $headers = array(
  25.                                                         'Accept: application/json',
  26.                                                         'Content-Type: application/json',
  27.                                                         'Content-Length: '.strlen($doc),
  28.                                                         "Authorization: Basic ".base64_encode("$user:$pass"),
  29.                                                 );          
  30.  
  31.                         $contextOptions = array('http' =>
  32.                                                                                                 array(
  33.                                                                                                         'method'  => 'POST',
  34.                                                                                                         'header'=>$headers,                                                                         $
  35.                                                                                                         'content' => $doc,
  36.                                                                                                         'timeout' => 60)                                                                            $
  37.                                                                                 );
  38.                         $sslContext = stream_context_create($contextOptions);  
  39.  
  40.                         $url = "$host/$db/_bulk_docs";
  41.                         $send = file_get_contents($url, NULL, $sslContext);
  42.  
  43.                         $ret = $send;
  44.                 }
  45.                else
  46.                 {
  47.                         $ret = -1;
  48.                 }
  49.  
  50.                 return $ret;
  51.  
  52.         }//end func
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement