Esempio n. 1
0
 /** @BeforeFeature */
 public static function prepareForTheFeature()
 {
     @http_delete(ELASTICSEARCH . '/cncflora_test0', []);
     @http_delete(ELASTICSEARCH . '/cncflora_test1', []);
     @http_delete(COUCHDB . '/cncflora_test0', []);
     @http_delete(COUCHDB . '/cncflora_test1', []);
     @http_put(ELASTICSEARCH . '/cncflora_test0', []);
     @http_put(ELASTICSEARCH . '/cncflora_test1', []);
     @http_put(COUCHDB . '/cncflora_test0', []);
     @http_put(COUCHDB . '/cncflora_test1', []);
     $file = file_get_contents(__DIR__ . "/load.json");
     $json = json_decode($file);
     $r = http_post(COUCHDB . "/cncflora_test0/_bulk_docs", array('docs' => $json));
     foreach ($json as $doc) {
         $doc->id = $doc->_id;
         foreach ($r as $revs) {
             if ($revs->id == $doc->_id) {
                 $doc->rev = $revs->rev;
                 $doc->_rev = $revs->rev;
             }
         }
         http_put(ELASTICSEARCH . '/cncflora_test0/' . $doc->metadata->type . '/' . $doc->_id, $doc);
     }
     sleep(1);
 }
Esempio n. 2
0
function s3_put($bucket, $args)
{
    $defaults = array('acl' => 'private');
    $args = array_merge($defaults, $args);
    # TO DO: account for PUT-ing of a file and
    # not just bits (aka $args['data'])
    $bytes_hashed = md5($args['data'], true);
    $bytes_enc = base64_encode($bytes_hashed);
    $date = date('D, d M Y H:i:s T');
    $path = "/{$bucket['id']}/{$args['id']}";
    $parts = array();
    $parts[] = 'PUT';
    $parts[] = $bytes_enc;
    $parts[] = $args['content_type'];
    $parts[] = $date;
    $parts[] = "x-amz-acl:{$args['acl']}";
    if ($args['meta']) {
        ksort($args['meta']);
        foreach ($args['meta'] as $k => $v) {
            $parts[] = "x-amz-meta-{$k}:{$v}";
        }
    }
    $parts[] = $path;
    $raw = implode("\n", $parts);
    $sig = s3_sign_auth_string($bucket, $raw);
    $sig = base64_encode($sig);
    $auth = "AWS {$bucket['key']}:{$sig}";
    $headers = array('Date' => $date, 'X-Amz-Acl' => $args['acl'], 'Content-Type' => $args['content_type'], 'Content-MD5' => $bytes_enc, 'Content-Length' => strlen($args['data']), 'Authorization' => $auth);
    if ($args['meta']) {
        foreach ($args['meta'] as $k => $v) {
            $headers["X-Amz-Meta-{$k}"] = $v;
        }
    }
    # See this? It's important. AWS freaks out at the mere presence
    # of the 'Transfer-Encoding' header. Thanks, Roy...
    $more = array('donotsend_transfer_encoding' => 1);
    $bucket_url = s3_get_bucket_url($bucket);
    # enurl-ify ?
    $object_url = $bucket_url . $args['id'];
    $rsp = http_put($object_url, $args['data'], $headers, $more);
    return $rsp;
}
Esempio n. 3
0
function http_multi(&$requests)
{
    $handles = array();
    $responses = array();
    foreach ($requests as $req) {
        $url = $req['url'];
        $method = isset($req['method']) ? strtoupper($req['method']) : 'GET';
        $body = is_array($req['body']) ? $req['body'] : null;
        $headers = is_array($req['headers']) ? $req['headers'] : array();
        $more = is_array($req['more']) ? $req['more'] : array();
        $more['return_curl_handle'] = 1;
        if ($method == 'HEAD') {
            $ch = http_head($url, $headers, $more);
        } else {
            if ($method == 'GET') {
                $ch = http_get($url, $headers, $more);
            } else {
                if ($method == 'POST') {
                    $ch = http_post($url, $body, $headers, $more);
                } else {
                    if ($method == 'DELETE') {
                        $ch = http_delete($url, $body, $headers, $more);
                    } else {
                        if ($method == 'PUT') {
                            $ch = http_put($url, $body, $headers, $more);
                        } else {
                            log_warning("http", "unsupported HTTP method : {$method}");
                            continue;
                        }
                    }
                }
            }
        }
        $handles[] = $ch;
    }
    # http://us.php.net/manual/en/function.curl-multi-init.php
    $mh = curl_multi_init();
    foreach ($handles as $ch) {
        curl_multi_add_handle($mh, $ch);
    }
    $active = null;
    $start = microtime_ms();
    # this syntax makes my eyes bleed but whatever...
    # (20110822/straup)
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    while ($active && $mrc == CURLM_OK) {
        if (curl_multi_select($mh) != -1) {
            do {
                $mrc = curl_multi_exec($mh, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        }
    }
    $end = microtime_ms();
    $GLOBALS['timings']['http_count'] += count($handlers);
    $GLOBALS['timings']['http_time'] += $end - $start;
    foreach ($handles as $ch) {
        $raw = curl_multi_getcontent($ch);
        $info = curl_getinfo($ch);
        curl_multi_remove_handle($mh, $ch);
        $rsp = _http_parse_response($raw, $info);
        $responses[] = $rsp;
    }
    curl_multi_close($mh);
    return $responses;
}
Esempio n. 4
0
<?php

session_start();
include "../conn/ws-conn.php";
include "../page-util.php";
$id = $_POST[id];
$username = $_POST[username];
$password = $_POST[password];
$data = array();
$data[id] = $id;
$data[username] = $username;
$data[password] = $password;
if ($id == "") {
    http_post("user", $data);
} else {
    http_put("user/{$id}", $data);
}
page_redirect("../index.php?action=user");