本文整理汇总了PHP中igbinary_serialize函数的典型用法代码示例。如果您正苦于以下问题:PHP igbinary_serialize函数的具体用法?PHP igbinary_serialize怎么用?PHP igbinary_serialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了igbinary_serialize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_space
function test_space($testname, $data)
{
$phplen = strlen(serialize($data));
$igbinarylen = strlen(igbinary_serialize($data));
printf(" php : %5u\n", $phplen);
printf(" igbinary: %5u (%.02f%%)\n", $igbinarylen, $igbinarylen * 100 / $phplen);
}
示例2: phpSerialize
/**
* @param mixed $data Data to serialize
* @param bool $useIgBinary Use igBinary extension if supported
*
* @return string
*/
protected function phpSerialize($data, $useIgBinary = true)
{
if ($this->isIgBinarySupported() && $useIgBinary) {
return igbinary_serialize($data);
}
return serialize($data);
}
示例3: freeze
/**
* Freezes this cache backend.
*
* All data in a frozen backend remains unchanged and methods which try to add
* or modify data result in an exception thrown. Possible expiry times of
* individual cache entries are ignored.
*
* On the positive side, a frozen cache backend is much faster on read access.
* A frozen backend can only be thawed by calling the flush() method.
*
* @return void
* @throws \RuntimeException
*/
public function freeze()
{
if ($this->frozen === true) {
throw new \RuntimeException(sprintf('The cache "%s" is already frozen.', $this->cacheIdentifier), 1323353176);
}
$cacheEntryFileExtensionLength = strlen($this->cacheEntryFileExtension);
for ($directoryIterator = new \DirectoryIterator($this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
if ($directoryIterator->isDot()) {
continue;
}
if ($cacheEntryFileExtensionLength > 0) {
$entryIdentifier = substr($directoryIterator->getFilename(), 0, -$cacheEntryFileExtensionLength);
} else {
$entryIdentifier = $directoryIterator->getFilename();
}
$this->cacheEntryIdentifiers[$entryIdentifier] = true;
$cacheEntryPathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
$lock = new Lock($cacheEntryPathAndFilename);
file_put_contents($cacheEntryPathAndFilename, $this->internalGet($entryIdentifier, false));
$lock->release();
}
$cachePathAndFileName = $this->cacheDirectory . 'FrozenCache.data';
$lock = new Lock($cachePathAndFileName);
if ($this->useIgBinary === true) {
file_put_contents($cachePathAndFileName, igbinary_serialize($this->cacheEntryIdentifiers));
} else {
file_put_contents($cachePathAndFileName, serialize($this->cacheEntryIdentifiers));
}
$lock->release();
$this->frozen = true;
}
示例4: serialize
protected function serialize ($value) {
if ($this->igbinary) {
return igbinary_serialize($value);
}
return serialize($value);
}
示例5: serialize
public function serialize($data)
{
if ($this->igbinary) {
return igbinary_serialize($data);
}
return serialize($data);
}
示例6: 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();
}
示例7: freeze
/**
* Freezes this cache backend.
*
* All data in a frozen backend remains unchanged and methods which try to add
* or modify data result in an exception thrown. Possible expiry times of
* individual cache entries are ignored.
*
* On the positive side, a frozen cache backend is much faster on read access.
* A frozen backend can only be thawed by calling the flush() method.
*
* @return void
* @throws \RuntimeException
*/
public function freeze()
{
if ($this->frozen === TRUE) {
throw new \RuntimeException(sprintf('The cache "%s" is already frozen.', $this->cacheIdentifier), 1323353176);
}
$cacheEntryFileExtensionLength = strlen($this->cacheEntryFileExtension);
for ($directoryIterator = new \DirectoryIterator($this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
if ($directoryIterator->isDot()) {
continue;
}
if ($cacheEntryFileExtensionLength > 0) {
$entryIdentifier = substr($directoryIterator->getFilename(), 0, -$cacheEntryFileExtensionLength);
} else {
$entryIdentifier = $directoryIterator->getFilename();
}
$this->cacheEntryIdentifiers[$entryIdentifier] = TRUE;
file_put_contents($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension, $this->get($entryIdentifier));
}
if ($this->useIgBinary === TRUE) {
file_put_contents($this->cacheDirectory . 'FrozenCache.data', igbinary_serialize($this->cacheEntryIdentifiers));
} else {
file_put_contents($this->cacheDirectory . 'FrozenCache.data', serialize($this->cacheEntryIdentifiers));
}
$this->frozen = TRUE;
}
示例8: set
/**
* Store data on the cache server.
*
* @param string $key Key we can use to retrieve the data.
* @param string|array $data Data to store on the cache server.
* @param int $expiration Time before the data expires on the cache server.
*
* @return bool Success/Failure.
* @access public
*/
public function set($key, $data, $expiration)
{
if ($this->connected === true && $this->ping() === true) {
return $this->server->set($key, $this->isRedis ? $this->IgBinarySupport ? igbinary_serialize($data) : serialize($data) : $data, $expiration);
}
return false;
}
示例9: testSerialize
/**
* @dataProvider getTestData
*/
public function testSerialize($value, $serialized, $expected = null)
{
if (!extension_loaded('igbinary')) {
$this->markTestSkipped('The igbinary extension must be loaded');
}
$serialized = igbinary_serialize($value);
parent::testSerialize($value, $serialized, $expected);
}
示例10: _tempData_serialize
private function _tempData_serialize($data)
{
if (true === $this->_has_igbinary_status) {
return igbinary_serialize($data);
} else {
return serialize($data);
}
}
示例11: serialize
private static function serialize($o)
{
$igbinary = extension_loaded('igbinary');
if ($igbinary) {
return @igbinary_serialize($o);
}
return @serialize($o);
}
示例12: serialize
/**
* @param mixed $val
* @return string
*/
function serialize($val)
{
if (function_exists('igbinary_serialize')) {
return \igbinary_serialize($val);
} else {
return \serialize($val);
}
}
示例13: _serialize
private function _serialize($data)
{
if ($this->_has_igbinary) {
return igbinary_serialize($data);
} else {
return serialize($data);
}
}
示例14: unpack
/**
*/
public function unpack($data)
{
$out = igbinary_unserialize($data);
if (!is_null($out) || $data == igbinary_serialize(null)) {
return $out;
}
throw new Horde_Pack_Exception('Error when unpacking serialized data.');
}
示例15: sendPacket
/**
* @TODO DESCR
* @param $p
*/
public function sendPacket($p)
{
if ($p === null) {
return;
}
$data = \igbinary_serialize($p);
$this->write(pack('N', mb_orig_strlen($data)) . $data);
}