本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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;
}
}
示例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);
}
示例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));
}
}
示例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();
}
示例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));
}
示例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));
示例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));
}
示例14: serialize
/**
* serialize -- by default with BSON
*
* @param object $object
*
* @return string
*/
function serialize($object)
{
return bson_encode($object);
}
示例15: var_dump
<?php
var_dump('' === bson_encode(null));