Ejemplo n.º 1
0
 /**
  * Handle a PUT request.
  *
  * @param string $key
  * @param array $headers
  * @return void
  * @throws TCHDBRequestException, TCException
  */
 private function handlePut($key, array $headers)
 {
     /**
      * Check for "Content-Length" header.
      */
     $length = -1;
     foreach ($headers as $name => $value) {
         if (!strcasecmp('Content-Length', $name)) {
             if (!is_string($value)) {
                 throw new TCHDBRequestException(self::$statuses[400], 400);
             }
             $length = (int) $value;
             break;
         }
     }
     if ($length < 0) {
         throw new TCHDBRequestException(self::$statuses[411], 411);
     } elseif ($length > $this->maxLength) {
         throw new TCHDBRequestException(self::$statuses[413], 413);
     }
     /**
      * Check for "Except: 100-continue" header.
      */
     foreach ($headers as $name => $value) {
         if (!strcasecmp('Expect', $name)) {
             if (!is_string($value)) {
                 throw new TCHDBRequestException(self::$statuses[400], 400);
             }
             if (stripos($value, '100-continue') !== false) {
                 $this->returnStatus(100);
                 usleep(1000);
             }
             break;
         }
     }
     /**
      * Read the request entity.
      */
     $body = '';
     while (strlen($body) < $length && !feof($this->conn)) {
         if (($buf = fread($this->conn, $length - strlen($body))) === false) {
             break;
         }
         $body .= $buf;
     }
     if (strlen($body) != $length) {
         $info = stream_get_meta_data($this->conn);
         $code = $info['timed_out'] ? 408 : 400;
         throw new TCHDBRequestException(self::$statuses[$code], $code);
     }
     /**
      * Put the request entity.
      */
     $this->hdb->put($key, $body);
     $url = 'http://' . $headers['Host'] . $headers['Request Url'];
     $this->returnResponse(201, $url, 'text/plain', array('Location' => $headers['Request Url']));
 }
Ejemplo n.º 2
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCBDB::KTINT64);
    $hdb->open('casket-i64.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    $hdb->put(2, 'hop');
    $hdb->put(0, 'step');
    $hdb->put(1, 'jump');
    echo $hdb->get(2), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Ejemplo n.º 3
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCHDB::KTBINARY, TCHDB::VTSERIALIZED);
    $hdb->open('casket-s.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    $hdb->put('foo', array('hop'));
    $hdb->put('bar', array('step', 'Step'));
    $hdb->put('baz', array('jump', 'Jump', 'JUMP'));
    print_r($hdb->get('foo'));
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s:%s", $key, print_r($value, true));
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
    $hdb->sync();
    unset($hdb);
    // destruct
    echo "--\n";
    $raw = new TCHDB();
    $raw->open('casket-s.hdb', TCHDB::OREADER);
    foreach ($raw as $key => $value) {
        printf("%s:%s\n", $key, $value);
    }
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Ejemplo n.º 4
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCBDB::KTINT64);
    $hdb->open('casket-i64s.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    // big number string representations
    $hdb->put('98765432102', 'hop');
    $hdb->put('98765432100', 'step');
    $hdb->put('98765432101', 'jump');
    echo $hdb->get('98765432102'), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Ejemplo n.º 5
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCBDB::KTINT64);
    $hdb->open('casket-i64f.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    // big number (more than 2147483647)
    // On 32-bit system, will be treated as a float.
    // On 64-bit system, will be treated as an integer.
    $hdb->put(98765432102.0, 'hop');
    $hdb->put(98765432100.0, 'step');
    $hdb->put(98765432101.0, 'jump');
    echo $hdb->get(98765432102.0), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Ejemplo n.º 6
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB();
    $hdb->open('casket.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    $hdb->put('foo', 'hop');
    $hdb->put('bar', 'step');
    $hdb->put('baz', 'jump');
    echo $hdb->get('foo'), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s:%s\n", $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}