当前位置: 首页>>代码示例>>PHP>>正文


PHP bson_encode函数代码示例

本文整理汇总了PHP中bson_encode函数的典型用法代码示例。如果您正苦于以下问题:PHP bson_encode函数的具体用法?PHP bson_encode怎么用?PHP bson_encode使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bson_encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bench

function bench($value, $n = 1000000)
{
    $benchmark = new Benchmark();
    $benchmark->add('serialize', function () use(&$value) {
        serialize($value);
    });
    $benchmark->add('json_encode', function () use(&$value) {
        json_encode($value);
    });
    if (function_exists('bin_encode')) {
        $benchmark->add('bin_encode', function () use(&$value) {
            bin_encode($value);
        });
    }
    if (function_exists('bson_encode')) {
        $benchmark->add('bson_encode', function () use(&$value) {
            bson_encode($value);
        });
    }
    if (function_exists('msgpack_pack')) {
        $benchmark->add('msgpack_pack', function () use(&$value) {
            msgpack_pack($value);
        });
    }
    if (function_exists('igbinary_serialize')) {
        $benchmark->add('igbinary_serialize', function () use(&$value) {
            igbinary_serialize($value);
        });
    }
    $benchmark->add('var_export', function () use(&$value) {
        var_export($value, true);
    });
    $benchmark->setCount($n);
    $benchmark->run();
}
开发者ID:ovr,项目名称:php-web-benchmarks,代码行数:35,代码来源:serialize.php

示例2: addProbe

 function addProbe($name)
 {
     $reflectProbe = new ReflectionClass('Probe');
     $probe = $reflectProbe->newInstanceArgs(func_get_args());
     if (gettype($name) !== 'string') {
         $name = $name['name'];
     }
     $this->probes->{$name} = $probe;
     $_this = $this;
     $probe->on('sample', function ($event) use($_this, $probe) {
         $sample = $event->getParams();
         $sample['probe'] = $probe;
         $_this->notify('sample', $sample);
         if (!isset($_this->samples)) {
             return;
         }
         $payload = $sample['payload'];
         $body = array('provider' => $_this->config['name'], 'module' => $_this->module, 'probe' => $probe->name, 'timestamp' => $payload->timestamp, 'hits' => $payload->hits, 'args' => $payload->args);
         $body = bson_encode($body);
         $probeKey = "{$_this->config['name']}.{$_this->module}.{$probe->name}";
         try {
             if ($probe->instant) {
                 publishSample($_this, $probeKey . '.all', $body);
             } else {
                 if (isset($sample['consumerId'])) {
                     publishSample($_this, $probeKey . '.' . $sample['consumerId'], $body);
                 }
             }
         } catch (Exception $e) {
             $_this->disconnect();
             return;
         }
     });
     return $probe;
 }
开发者ID:rstuven,项目名称:php-notrace,代码行数:35,代码来源:provider.php

示例3: opQuery

 public function opQuery($fullCollectionName, array $query, $numberToSkip, $numberToReturn, $flags, $timeout, array $returnFieldsSelector = null)
 {
     $data = pack('Va*VVa*', $flags, "{$fullCollectionName}", $numberToSkip, $numberToReturn, bson_encode($query));
     if ($returnFieldsSelector) {
         $data .= bson_encode($returnFieldsSelector);
     }
     return $this->putReadMessage(self::OP_QUERY, $data, $timeout);
 }
开发者ID:Wynncraft,项目名称:mongofill,代码行数:8,代码来源:Protocol.php

示例4: send_request

 protected function send_request(GoRpcRequest $req)
 {
     $this->write(bson_encode($req->header));
     if ($req->body === NULL) {
         $this->write(bson_encode(array()));
     } else {
         $this->write(bson_encode($req->body));
     }
 }
开发者ID:Robert-Xie,项目名称:vitess,代码行数:9,代码来源:bsonrpc.php

示例5: parser_validates_bson_data

 /** @test */
 public function parser_validates_bson_data()
 {
     if (function_exists('bson_decode')) {
         $expected = array('status' => 123, 'message' => 'hello world');
         $payload = bson_encode($expected);
         $parser = new Parser();
         $this->assertEquals($expected, $parser->bson($payload));
     }
 }
开发者ID:robertomiguel,项目名称:autorizador,代码行数:10,代码来源:BSONTest.php

示例6: sendRequest

 protected function sendRequest(VTContext $ctx, GoRpcRequest $req)
 {
     $this->write($ctx, bson_encode($req->header));
     if ($req->body === NULL) {
         $this->write($ctx, bson_encode(array()));
     } else {
         $this->write($ctx, bson_encode($req->body));
     }
 }
开发者ID:richarwu,项目名称:vitess,代码行数:9,代码来源:BsonRpcClient.php

示例7: send

 function send($msg)
 {
     $serialized_message = bson_encode($msg);
     $len = strlen($serialized_message);
     $off = 0;
     while ($off < $len) {
         $len_write = socket_write($this->socket, $off == 0 ? $serialized_message : $substr($serialized_message, $off), $len - $off);
         if (!$len_write) {
             throw new Exception("write error");
         }
         $off += $len_write;
     }
 }
开发者ID:recrack,项目名称:KakaoChatFriendAPI,代码行数:13,代码来源:KakaoBot.class.php

示例8: convertDataObjectSet

 /**
  * Generate a BSON representation of the given {@link SS_List}.
  *
  * @param SS_List $set
  * @param null    $fields
  *
  * @return string BSON
  */
 public function convertDataObjectSet(SS_List $set, $fields = null)
 {
     $this->checkForBson();
     $items = [];
     foreach ($set as $do) {
         /** @var DataObject $do */
         if (!$do->canView()) {
             continue;
         }
         $items[] = $this->convertDataObjectToJSONObject($do, $fields);
     }
     $serobj = ArrayData::array_to_object(["totalSize" => is_numeric($this->totalSize) ? $this->totalSize : null, "items" => $items]);
     /** @noinspection PhpUndefinedFunctionInspection */
     return bson_encode($serobj);
 }
开发者ID:helpfulrobot,项目名称:sheerwater-ss-bson-data-formatter,代码行数:23,代码来源:BSONDataFormatter.php

示例9: cacheObject

 /**
  * Method called when object received.
  * @param object Object.
  * @return void
  */
 public function cacheObject($o)
 {
     if (Daemon::$config->logevents->value) {
         Daemon::log(__METHOD__ . '(' . json_encode($o) . ')');
     }
     if (isset($o['_key'])) {
         $this->cache->set($o['_key'], bson_encode($o));
         $this->cache->set('_id.' . (string) $o['_id'], $o['_key']);
     }
     if (isset($o['_ev'])) {
         $o['name'] = $o['_ev'];
         if (Daemon::$config->logevents->value) {
             Daemon::log('MongoNode send event ' . $o['name']);
         }
         $this->RTEPClient->client->request(array('op' => 'event', 'event' => $o));
     }
 }
开发者ID:J3FF3,项目名称:phpdaemon,代码行数:22,代码来源:MongoNode.php

示例10: bench

function bench($value, $n = 1000000)
{
    $benchmark = new Benchmark();
    $serialized = serialize($value);
    $benchmark->add('unserialize', function () use(&$serialized) {
        unserialize($serialized);
    });
    $jsonEncoded = json_encode($value);
    $benchmark->add('json_decode', function () use(&$jsonEncoded) {
        json_decode($jsonEncoded);
    });
    if (function_exists('bin_decode')) {
        $binEncoded = bin_encode($value);
        $benchmark->add('bin_decode', function () use(&$binEncoded) {
            bin_decode($binEncoded);
        });
    }
    if (function_exists('bson_decode')) {
        $bsonEncoded = bson_encode($value);
        $benchmark->add('bson_decode', function () use(&$bsonEncoded) {
            bson_decode($bsonEncoded);
        });
    }
    if (function_exists('msgpack_pack')) {
        $msgPack = msgpack_pack($value);
        $benchmark->add('msgpack_unpack', function () use(&$msgPack) {
            msgpack_unpack($msgPack);
        });
    }
    if (function_exists('igbinary_unserialize')) {
        $igbinarySerialized = igbinary_serialize($value);
        $benchmark->add('igbinary_unserialize', function () use(&$igbinarySerialized) {
            igbinary_unserialize($igbinarySerialized);
        });
    }
    $benchmark->setCount($n);
    $benchmark->run();
}
开发者ID:ovr,项目名称:php-web-benchmarks,代码行数:38,代码来源:unserialize.php

示例11: testEncodeDate

 public function testEncodeDate()
 {
     $timestamp = strtotime('2014-03-01 14:30:33 UTC', 123120);
     $input = new MongoDate($timestamp);
     $bson = bson_encode(['date' => $input]);
     $out = bson_decode($bson)['date'];
     $this->assertEquals($input, $out);
     $this->assertEquals('1300000009646174650028bb0d7e4401000000', bin2hex($bson));
     $input = new MongoDate(-$timestamp, 123120);
     $bson = bson_encode(['date' => $input]);
     $out = bson_decode($bson)['date'];
     $this->assertEquals($input, $out);
     $this->assertEquals('130000000964617465005345f281bbfeffff00', bin2hex($bson));
 }
开发者ID:radford,项目名称:mongofill,代码行数:14,代码来源:BsonTest.php

示例12: chr

<?php

$expected = chr(236) . chr(81) . chr(184) . chr(30) . chr(133) . chr(235) . chr(16) . chr(64);
var_dump($expected === bson_encode(4.23));
开发者ID:badlamer,项目名称:hhvm,代码行数:4,代码来源:bson_encode-003.php

示例13: remove

 public function remove($col, $cond = array(), $key = '')
 {
     if (strpos($col, '.') === FALSE) {
         $col = $this->dbname . '.' . $col;
     }
     if (is_string($cond)) {
         $cond = new MongoCode($cond);
     }
     $reqId = $this->request($key, self::OP_DELETE, "" . $col . "" . "" . bson_encode($cond));
 }
开发者ID:svcorp77,项目名称:phpdaemon,代码行数:10,代码来源:MongoClient.php

示例14: serialize

 /**
  *  serialize -- by default with BSON
  *
  *  @param object $object
  *
  *  @return string
  */
 function serialize($object)
 {
     return bson_encode($object);
 }
开发者ID:284099857,项目名称:ActiveMongo,代码行数:11,代码来源:Cache.php

示例15: var_dump

<?php

var_dump('' === bson_encode(null));
开发者ID:badlamer,项目名称:hhvm,代码行数:3,代码来源:bson_encode-001.php


注:本文中的bson_encode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。