/** * @param mixed $data Data to unserialize * @param bool|true $useIgBinary Use igBinary extension if supported * * @return string */ protected function phpUnserialize($data, $useIgBinary = true) { if ($this->isIgBinarySupported() && $useIgBinary) { return igbinary_unserialize($data); } return unserialize($data); }
public function unserialize($data) { if ($this->igbinary) { return igbinary_unserialize($data); } return unserialize($data); }
protected function unserialize ($value) { if ($this->igbinary) { return igbinary_unserialize($value); } return unserialize($value); }
/** * Attempt to retrieve a value from the cache server, if not set it. * * @param string $key Key we can use to retrieve the data. * * @return bool|string False on failure or String, data belonging to the key. * @access public */ public function get($key) { if ($this->connected === true && $this->ping() === true) { $data = $this->server->get($key); return $this->isRedis ? $this->IgBinarySupport ? igbinary_unserialize($data) : unserialize($data) : $data; } return false; }
private function _tempData_unserialize($data) { if (true === $this->_has_igbinary_status) { return igbinary_unserialize($data); } else { return unserialize($data); } }
private static function unserialize($o) { $igbinary = extension_loaded('igbinary'); if ($igbinary) { return @igbinary_unserialize($o); } return @unserialize($o); }
/** */ 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.'); }
/** * @param $val * @return mixed */ function unserialize($val) { if (function_exists('igbinary_unserialize')) { return \igbinary_unserialize($val); } else { return \unserialize($val); } }
private function _unserialize($data) { if ($this->_has_igbinary) { return igbinary_unserialize($data); } else { return unserialize($data); } }
/** * @return array */ public static function ADecode($sData) { $ret = igbinary_unserialize($sData); if (null === $ret) { return false; } return $ret; }
protected function convert($input) { if (function_exists('igbinary_unserialize')) { $result = igbinary_unserialize($input); } else { $result = array(); } return $result; }
/** * unserialize * * @param string $value * * @return mixed */ public function unserialize($value) { if (function_exists('igbinary_unserialize')) { return igbinary_unserialize($value); } else { // fallback return unserialize($value); } }
/** * Deserialize igbinary string to PHP value * * @param string|binary $serialized * @param array $opts * @return mixed * @throws Zend_Serializer_Exception on igbinary error */ public function unserialize($serialized, array $opts = array()) { $ret = igbinary_unserialize($serialized); if ($ret === null && $serialized !== self::$_serializedNull) { $lastErr = error_get_last(); throw new Zend_Serializer_Exception($lastErr['message']); } return $ret; }
/** * 解密 * @param $data 加密后的字符串; * @return bool|mixed|string 返回加密前的数据类型。 */ public function decrypt($data) { if (empty($data)) { return ''; } $data = explode('?', $data)[0]; $data = base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT)); $data = Yii::$app->getSecurity()->decryptByKey($data, self::$_key); return igbinary_unserialize($data); }
function test_speed_unserialize_igbinary($data, $loops) { $serdata = igbinary_serialize($data); $start = microtime(true); for ($i = 0; $i < $loops; ++$i) { $tmp = igbinary_unserialize($serdata); } $end = microtime(true); return $end - $start; }
/** * Deserialize igbinary string to PHP value * * @param string|binary $serialized * @param array $opts * @return mixed * @throws Zend_Serializer_Exception on igbinary error */ public function unserialize($serialized, array $opts = array()) { $ret = igbinary_unserialize($serialized); if ($ret === null && $serialized !== self::$_serializedNull) { $lastErr = error_get_last(); require_once PHP_LIBRARY_PATH . 'Zend/Serializer/Exception.php'; throw new Zend_Serializer_Exception($lastErr['message']); } return $ret; }
/** * Deserialize igbinary string to PHP value * * @param string $serialized * @return mixed * @throws Exception\RuntimeException on igbinary error */ public function unserialize($serialized) { if ($serialized === static::$serializedNull) { return null; } ErrorHandler::start(); $ret = igbinary_unserialize($serialized); $err = ErrorHandler::stop(); if ($ret === null) { throw new Exception\RuntimeException('Unserialization failed', 0, $err); } return $ret; }
public static function unpack($input_string) { $mark_length = strlen(self::PACKED_MARK); if (substr($input_string, 0, $mark_length) != self::PACKED_MARK) { return $input_string; } $string = substr($input_string, $mark_length); $string = base64_decode($string); if (empty($string)) { return $input_string; } if (function_exists("igbinary_unserialize")) { return igbinary_unserialize($string); } else { return unserialize($string); } }
public function __construct($serializable=false) {/*{{{*/ $this->_beginTime = microtime(true); $inputs = array_merge($_GET, $_POST); if ($serializable) { //error_log(print_r($inputs, true), 3, '/tmp/a'); $params = igbinary_unserialize(rawurldecode($inputs['data'])); //error_log(print_r('===='.$params, true), 3, '/tmp/a'); $this->args = $params['args']; $this->options = $params['options']; //$this->args = unserialize($inputs['data']); //$this->options = unserialize($inputs['options']); $this->service = $inputs['service']; $this->do = $inputs['do']; } }/*}}}*/
/** * Get cell at a specific coordinate * * @param string $pCoord Coordinate of the cell * @throws PHPExcel_Exception * @return PHPExcel_Cell Cell that was found, or null if not found */ public function getCacheData($pCoord) { if ($pCoord === $this->currentObjectID) { return $this->currentObject; } $this->storeData(); // Check if the entry that has been requested actually exists if (!isset($this->cellCache[$pCoord])) { // Return null if requested entry doesn't exist in cache return null; } // Set current entry to the requested entry $this->currentObjectID = $pCoord; $this->currentObject = igbinary_unserialize($this->cellCache[$pCoord]); // Re-attach this as the cell's parent $this->currentObject->attach($this); // Return requested entry return $this->currentObject; }
/** * Prepares a cached item. * * Checks that items are either permanent or did not expire, and unserializes * data as appropriate. * * @param $cache * An item loaded from cache_get() or cache_get_multiple(). * * @return bool|mixed * The item with data unserialized as appropriate or FALSE if there is no * valid item to load. */ protected function prepareItem($cache) { global $user; if (!isset($cache->data)) { return false; } // If the cached data is temporary and subject to a per-user minimum // lifetime, compare the cache entry timestamp with the user session // cache_expiration timestamp. If the cache entry is too old, ignore it. if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && isset($_SESSION['cache_expiration'][$this->bin]) && $_SESSION['cache_expiration'][$this->bin] > $cache->created) { // Ignore cache data that is too old and thus not valid for this user. return false; } // If the data is permanent or not subject to a minimum cache lifetime, // unserialize and return the cached data. if ($cache->serialized) { $cache->data = igbinary_unserialize($cache->data); } return $cache; }
public function unserialize($data) { $serialize = strtolower($this->get('serialize')); if ('igbinary' == $serialize) { return igbinary_unserialize($data); } if ('json' == $serialize) { return json_decode($data, TRUE); } if ('php' == $serialize) { return unserialize($data); } if (extension_loaded('igbinary')) { return igbinary_unserialize($data); } if (extension_loaded('json')) { return json_decode($data, TRUE); } return unserialize($data); }
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(); }
/** * Called when new data received. * @return void */ public function onRead() { start: if ($this->state === self::STATE_ROOT) { if (false === ($r = $this->readExact(4))) { return; // not ready yet } $u = unpack('N', $r); $this->packetLength = $u[1]; $this->state = self::STATE_CONTENT; } if ($this->state === self::STATE_CONTENT) { if (false === ($packet = $this->readExact($this->packetLength))) { $this->setWatermark($this->packetLength, $this->packetLength); return; // not ready yet } $this->setWatermark(4, 0xffff); $this->state = self::STATE_ROOT; $this->onPacket(igbinary_unserialize($packet)); } goto start; }
/** * Unpack signature * * @param string $signature * @return mixed */ protected function _unpack($signature) { return igbinary_unserialize($signature); }
/** * */ protected function parseResponse($data) { if (!array_key_exists('extra', $data)) { throw new \LogicException('Not a valid Response stored by Xenzilla\\Memcached'); } if ($data['extra'] & self::MEMC_VAL_COMPRESSED) { $body = gzuncompress($data['body']); } else { $body = $data['body']; } $type = $data['extra'] & self::MEMC_VAL_TYPE_MASK; switch ($type) { case self::MEMC_VAL_IS_STRING: $body = strval($body); break; case self::MEMC_VAL_IS_LONG: $body = intval($body); break; case self::MEMC_VAL_IS_DOUBLE: $body = doubleval($body); break; case self::MEMC_VAL_IS_BOOL: $body = $body ? TRUE : FALSE; break; case self::MEMC_VAL_IS_SERIALIZED: switch ($this->options[self::OPT_SERIALIZER]) { case self::SERIALIZER_PHP: $body = unserialize($body); break; case self::SERIALIZER_IGBINARY: $body = igbinary_unserialize($body); break; case self::SERIALIZER_JSON: $body = json_decode($body); break; } break; } return $body; }
/** * Tries to load the reflection data from the compile time cache. * * The compile time cache is only supported for Development context and thus * this function will return in any other context. * * If no reflection data was found, this method will at least load the precompiled * reflection data of any possible frozen package. Even if precompiled reflection * data could be loaded, FALSE will be returned in order to signal that other * packages still need to be reflected. * * @return boolean TRUE if reflection data could be loaded, otherwise FALSE */ protected function loadClassReflectionCompiletimeCache() { $data = $this->reflectionDataCompiletimeCache->get('ReflectionData'); if ($data !== false) { foreach ($data as $propertyName => $propertyValue) { $this->{$propertyName} = $propertyValue; } return true; } if (!$this->context->isDevelopment()) { return false; } $useIgBinary = extension_loaded('igbinary'); foreach ($this->packageManager->getActivePackages() as $packageKey => $package) { if (!$this->packageManager->isPackageFrozen($packageKey)) { continue; } $pathAndFilename = $this->getPrecompiledReflectionStoragePath() . $packageKey . '.dat'; if (!file_exists($pathAndFilename)) { continue; } $data = $useIgBinary ? igbinary_unserialize(file_get_contents($pathAndFilename)) : unserialize(file_get_contents($pathAndFilename)); foreach ($data as $propertyName => $propertyValue) { $this->{$propertyName} = \TYPO3\Flow\Utility\Arrays::arrayMergeRecursiveOverrule($this->{$propertyName}, $propertyValue); } } return false; }
/** * Return PHP value derived from string * @return string * @param $arg mixed **/ function unserialize($arg) { switch (strtolower($this->hive['SERIALIZER'])) { case 'igbinary': return igbinary_unserialize($arg); case 'json': return json_decode($arg); default: return unserialize($arg); } }
/** * Sets a reference to the cache frontend which uses this backend and * initializes the default cache directory. * * This method also detects if this backend is frozen and sets the internal * flag accordingly. * * TYPO3 v4 note: This method is different between TYPO3 v4 and FLOW3 * because the Environment class to get the path to a temporary directory * does not exist in v4. * * @param \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache The cache frontend * @return void */ public function setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache) { parent::setCache($cache); if (file_exists($this->cacheDirectory . 'FrozenCache.data')) { $this->frozen = TRUE; if ($this->useIgBinary === TRUE) { $this->cacheEntryIdentifiers = igbinary_unserialize(file_get_contents($this->cacheDirectory . 'FrozenCache.data')); } else { $this->cacheEntryIdentifiers = unserialize(file_get_contents($this->cacheDirectory . 'FrozenCache.data')); } } }
/** * Unserialize the course with the best serializer available */ public static function unserialize($course) { if (extension_loaded('igbinary')) { return igbinary_unserialize($course); } else { return unserialize($course); } }