本文整理汇总了PHP中crc32函数的典型用法代码示例。如果您正苦于以下问题:PHP crc32函数的具体用法?PHP crc32怎么用?PHP crc32使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了crc32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeUrl
public static function writeUrl(&$db, $loc, $lastMod = null, $changeFreq = null, $priority = null, $tableName = 'sitemap')
{
try {
$loc = trim($loc);
$checksum = crc32($loc);
/* get the host name from url */
preg_match('@^(?:https?:\\/\\/)?((?:www\\.)?[^\\/]+)@i', $loc, $matches);
$host = $matches[1];
$row = $db->select_1('select * from sitemap where loc = %s', $loc);
/* new location */
if (is_null($row)) {
$db->insert('sitemap', 'checksum = \'%l\'::bigint', $checksum, 'host = %s', $host, 'loc = %s', $loc, 'last_mod = %T', $lastMod, 'change_freq = %S', $changeFreq, 'priority = %l', is_null($priority) ? 'NULL' : $priority);
/* update as details have changed */
} elseif ($row->t_last_mod != $lastMod || $row->s_change_freq != $changeFreq || $row->s_priority != $priority) {
$db->update_1('sitemap', 'loc = %s', $loc, 'last_mod = %T', $lastMod, 'change_freq = %S', $changeFreq, 'priority = %l', is_null($priority) ? 'NULL' : $priority);
}
/* nulling used variables (big sitemaps need every scrap of memory!) */
$row = null;
$host = null;
$checksum = null;
$matches = null;
} catch (Exception $e) {
Atsumi::error__listen($e);
}
}
示例2: generatePath
/**
* Generate a path for the uploading file
*
* @param string $fileName The name of file for path generate
* @param integer $splitLen Name length of each sub folder
*
* @return string The generated path
*/
protected function generatePath($fileName, $splitLen = 3)
{
$resultName = '';
$validFileName = preg_replace('/([^a-zA-Z0-9\\x{007f}-\\x{ffe5}\\-\\_\\@]+)+/iu', '~', pathinfo($fileName, PATHINFO_FILENAME));
while (strpos($validFileName, '~~') !== false) {
$validFileName = str_replace('~~', '~', $validFileName);
}
$fileNameLen = strlen($validFileName);
$fileNameLastIdx = $fileNameLen - 1;
$fileNameSplitLen = $fileNameLen - $splitLen;
if ($fileNameLen >= $splitLen) {
for ($charLoop = 0; $charLoop < $fileNameSplitLen;) {
for ($elLoop = 0; $elLoop < $splitLen; $elLoop++) {
$resultName .= $validFileName[$charLoop];
if (++$charLoop > $fileNameLastIdx) {
break;
}
}
$resultName .= '/';
}
$resultName = substr($resultName, 0, strlen($resultName) - 1);
} else {
$resultName = date('Y') . '/' . abs((int) (crc32(date('m/w')) / 10240));
}
return $resultName;
}
示例3: getUrlPageName
public function getUrlPageName()
{
if (static::$urlPageName !== null) {
return static::$urlPageName;
}
/*
* Cache
*/
$key = 'urlMaker' . $this->urlComponentName . crc32(get_class($this));
$cached = Cache::get($key, false);
if ($cached !== false && ($cached = @unserialize($cached)) !== false) {
$filePath = array_get($cached, 'path');
$mtime = array_get($cached, 'mtime');
if (!File::isFile($filePath) || $mtime != File::lastModified($filePath)) {
$cached = false;
}
}
if ($cached !== false) {
return static::$urlPageName = array_get($cached, 'fileName');
}
$page = Page::useCache()->whereComponent($this->urlComponentName, 'isPrimary', '1')->first();
if (!$page) {
throw new ApplicationException(sprintf('Unable to a find a primary component "%s" for generating a URL in %s.', $this->urlComponentName, get_class($this)));
}
$baseFileName = $page->getBaseFileName();
$filePath = $page->getFullPath();
$cached = ['path' => $filePath, 'fileName' => $baseFileName, 'mtime' => @File::lastModified($filePath)];
Cache::put($key, serialize($cached), Config::get('cms.parsedPageCacheTTL', 1440));
return static::$urlPageName = $baseFileName;
}
示例4: send
public function send($to, $subject, $message, $add_hostname_to_subject = false, $no_cache = false, $cc = false)
{
$function_cache_id = false;
$args = func_get_args();
foreach ($args as $k => $v) {
$function_cache_id = $function_cache_id . serialize($k) . serialize($v);
}
$function_cache_id = __FUNCTION__ . crc32($function_cache_id);
$cache_group = "notifications/email";
$cache_content = mw()->cache_manager->get($function_cache_id, $cache_group);
if ($no_cache == false and $cache_content != false) {
return $cache_content;
}
$email_from = mw()->option_manager->get('email_from', 'email');
if ($email_from == false or $email_from == '') {
} else {
if (!filter_var($email_from, FILTER_VALIDATE_EMAIL)) {
}
}
if ($add_hostname_to_subject != false) {
$subject = '[' . mw()->url_manager->hostname() . '] ' . $subject;
}
if (isset($to) and filter_var($to, FILTER_VALIDATE_EMAIL)) {
$this->exec_send($to, $subject, $message);
if (isset($cc) and $cc != false and filter_var($cc, FILTER_VALIDATE_EMAIL)) {
$this->exec_send($cc, $subject, $message);
}
mw()->cache_manager->save(true, $function_cache_id, $cache_group, 30);
return true;
} else {
return false;
}
}
示例5: build
/**
* {@inheritdoc}
*/
public function build($config, array $options = null)
{
$adapter = null;
$cacheTtlKey = $this->getCacheTtlKey($config);
// Check if a cache was provided
if (isset($options['cache.adapter']) && is_string($config)) {
$adapter = $options['cache.adapter'];
$ttl = isset($options[$cacheTtlKey]) ? $options[$cacheTtlKey] : 3600;
$cacheKey = 'guzzle' . crc32($config);
// Check if the instantiated data is in the cache
if ($cached = $adapter->fetch($cacheKey)) {
return $cached;
}
}
// Get the name of the class to instantiate for the type of data
$factory = $this->getFactory($config);
if (!$factory || is_string($factory)) {
return $this->throwException($factory);
}
$result = $factory->build($config, $options);
if ($adapter) {
$adapter->save($cacheKey, $result, $ttl);
}
return $result;
}
示例6: execute
public function execute()
{
if (Session::get_state() != Session::ST_LIFE) {
self::set_client_command('refresh', array('url' => 'self'));
self::set_result(FALSE);
return;
}
if (strlen($this->message) > 65000) {
throw new Command_exception('text length error', get_string('errors', 'text_length_error'));
}
$captcha_lib = Loader::get_library('captcha');
if (!$captcha_lib->check($this->captcha)) {
throw new Command_exception('captcha error', get_string('errors', 'captcha_error'));
}
require_once BASEPATH . 'global/cache.php';
$query = array();
$query['%text'] = Security::sanitize_text($this->message);
$query['%name'] = Security::sanitize_text($this->name);
$query['%email'] = Security::sanitize_text($this->email);
$query['%quote_id'] = intval($this->quote_id);
$query['%page'] = Cache::generate_key(TRUE);
$query['%avatar'] = abs(crc32($this->email)) % self::AVATAR_COUNT;
foreach ($query as $key => $value) {
if (!in_array($key, array('%quote_id', '%avatar')) and empty($value)) {
throw new Command_exception('empty text error', get_string('errors', 'empty_field'));
}
}
db::simple_query(self::Q_SET_COMMENT, $query, TRUE);
Cache::reset($query['%page']);
self::set_client_command('refresh', array('url' => 'self'));
}
示例7: listArticles
static function listArticles()
{
$PAGE_SIZE = 2000;
$dbr = wfGetDB(DB_SLAVE);
$titles = array();
for ($page = 0;; $page++) {
$offset = $PAGE_SIZE * $page;
$sql = "SELECT page_id, page_title, page_touched FROM page WHERE page_namespace = " . NS_MAIN . " AND page_is_redirect = 0 ORDER BY page_touched DESC LIMIT {$offset},{$PAGE_SIZE}";
$res = $dbr->query($sql, __FILE__);
if (!$res->numRows()) {
break;
}
foreach ($res as $row) {
$title = Title::newFromDBKey($row->page_title);
if (!$title) {
continue;
}
$text = $title->getText();
$crc = crc32($text);
$titles[] = array('uri' => $title->getFullUrl(), 'percent' => $crc % 100);
}
}
usort($titles, function ($i, $j) {
if ($i['percent'] == $j['percent']) {
return strcasecmp($i['uri'], $j['uri']);
} elseif ($i['percent'] < $j['percent']) {
return -1;
} else {
return 1;
}
});
foreach ($titles as $title) {
print $title['uri'] . "\n";
}
}
示例8: getDataCacheKey
/**
* Returns cache key for some request to carrier data service
*
* @param string|array $key
* @return string
*/
public function getDataCacheKey($key)
{
if (is_array($key)) {
$key = implode(',', array_keys($key));
}
return crc32($key);
}
示例9: initialize
/**
* Initializes the cookie class.
*/
private static function initialize()
{
if (self::$initialized) {
return;
}
self::$prefix = crc32(APP_COOKIE_SALT) . '_';
}
示例10: tName
public function tName($user, $talbeName = NULL)
{
$tableName = parent::tName($tableName);
$key = is_numeric($user) ? $user : abs(crc32(trim($user)));
$key = $key % self::TABLE_NUM;
return $tableName . '_' . $key;
}
示例11: optimize
public function optimize($buffer)
{
$output = '';
// matched buffer comes in from preg_replace_callback() as array
$buffer = $buffer[0];
$dom = new DOMDocument();
$dom->loadHTML($buffer);
$html = simplexml_import_dom($dom);
// gather file names -
// get URL's for each CSS file in each CSS tag of the HTML block
$files = array();
foreach ($html->head->link as $link) {
// filter out things like favicon
if ((string) $link['rel'] == 'stylesheet') {
$file = trim((string) $link['href']);
$files[] = trim($file, '/');
}
}
// build the combined, minified output file
// the latest mod time of the set is in output file name
try {
$outfile = $this->_getName($files);
$this->_phing->log("Building {$this->_toDir}/{$outfile}");
$this->_build($outfile, $files);
} catch (Exception $e) {
throw new BuildException($e->getMessage());
}
// output the static CSS tag
$twoBitValue = 0x3 & crc32("{$outfile}");
$host = str_replace('?', $twoBitValue, $this->_host);
$path = "http://{$host}/{$outfile}";
$output = "<link href=\"{$path}\" rel=\"stylesheet\" type=\"text/css\" />\n";
return $output;
}
示例12: onConfigSave
/**
* Checks that configuration complies with its schema on config save.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The configuration event.
*
* @throws \Drupal\Core\Config\Schema\SchemaIncompleteException
* Exception thrown when configuration does not match its schema.
*/
public function onConfigSave(ConfigCrudEvent $event)
{
// Only validate configuration if in the default collection. Other
// collections may have incomplete configuration (for example language
// overrides only). These are not valid in themselves.
$saved_config = $event->getConfig();
if ($saved_config->getStorage()->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) {
return;
}
$name = $saved_config->getName();
$data = $saved_config->get();
$checksum = crc32(serialize($data));
$exceptions = array('config_schema_test.noschema', 'config_schema_test.someschema', 'config_schema_test.schema_data_types', 'config_schema_test.no_schema_data_types', 'config_test.dynamic.system');
if (!in_array($name, $exceptions) && !isset($this->checked[$name . ':' . $checksum])) {
$this->checked[$name . ':' . $checksum] = TRUE;
$errors = $this->checkConfigSchema($this->typedManager, $name, $data);
if ($errors === FALSE) {
throw new SchemaIncompleteException(String::format('No schema for @config_name', array('@config_name' => $name)));
} elseif (is_array($errors)) {
$text_errors = [];
foreach ($errors as $key => $error) {
$text_errors[] = String::format('@key @error', array('@key' => $key, '@error' => $error));
}
throw new SchemaIncompleteException(String::format('Schema errors for @config_name with the following errors: @errors', array('@config_name' => $name, '@errors' => implode(', ', $text_errors))));
}
}
}
示例13: __construct
/**
* コンストラクタ
*/
public function __construct($aThread, $matome = false)
{
parent::__construct($aThread, $matome);
global $_conf;
$this->_url_handlers = array('plugin_linkThread', 'plugin_link2chSubject');
// +Wiki
if (isset($GLOBALS['linkPluginCtl'])) {
$this->_url_handlers[] = 'plugin_linkPlugin';
}
if (isset($GLOBALS['replaceImageUrlCtl'])) {
$this->_url_handlers[] = 'plugin_replaceImageUrl';
}
if (P2_IMAGECACHE_AVAILABLE == 2) {
$this->_url_handlers[] = 'plugin_imageCache2';
} elseif ($_conf['preview_thumbnail']) {
$this->_url_handlers[] = 'plugin_viewImage';
}
if ($_conf['link_youtube']) {
$this->_url_handlers[] = 'plugin_linkYouTube';
}
if ($_conf['link_niconico']) {
$this->_url_handlers[] = 'plugin_linkNicoNico';
}
$this->_url_handlers[] = 'plugin_linkURL';
// imepitaのURLを加工してImageCache2させるプラグインを登録
if (P2_IMAGECACHE_AVAILABLE == 2) {
$this->addURLHandler(array($this, 'plugin_imepitaToImageCache2'));
}
// サムネイル表示制限数を設定
if (!isset($GLOBALS['pre_thumb_unlimited']) || !isset($GLOBALS['pre_thumb_limit'])) {
if (isset($_conf['pre_thumb_limit']) && $_conf['pre_thumb_limit'] > 0) {
$GLOBALS['pre_thumb_limit'] = $_conf['pre_thumb_limit'];
$GLOBALS['pre_thumb_unlimited'] = false;
} else {
$GLOBALS['pre_thumb_limit'] = null;
// ヌル値だとisset()はfalseを返す
$GLOBALS['pre_thumb_unlimited'] = true;
}
}
$GLOBALS['pre_thumb_ignore_limit'] = false;
// アクティブモナー初期化
if (P2_ACTIVEMONA_AVAILABLE) {
ExpackLoader::initActiveMona($this);
}
// ImageCache2初期化
if (P2_IMAGECACHE_AVAILABLE == 2) {
ExpackLoader::initImageCache($this);
}
// 非同期レスポップアップ・SPM初期化
$js_id = sprintf('%u', crc32($this->thread->keydat));
if ($this->_matome) {
$this->asyncObjName = "t{$this->_matome}asp{$js_id}";
$this->spmObjName = "t{$this->_matome}spm{$js_id}";
} else {
$this->asyncObjName = "asp{$js_id}";
$this->spmObjName = "spm{$js_id}";
}
// 名無し初期化
$this->setBbsNonameName();
}
示例14: getNextValueByShareMemory
/**
* 通过本机共享内存件来生成一个auto_increment序列
*
* 序列类似MySQL的auto_increment
*
* @access private
* @param void
* @return mixed
*/
function getNextValueByShareMemory()
{
$addr = '127.0.0.1';
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$addr = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (!empty($_SERVER['SERVER_ADDR'])) {
$addr = $_SERVER['SERVER_ADDR'];
}
$skey = 'global_serial_generator_seed_' . $addr;
$ikey = crc32($skey);
$sem = $shm = null;
$retry_times = 1;
do {
$sem = sem_get($ikey, 1, 0777);
$shm = shm_attach($ikey, 128, 0777);
if (is_resource($sem) && is_resource($shm)) {
break;
}
$cmd = "ipcrm -M 0x00000000; ipcrm -S 0x00000000; ipcrm -M {$ikey} ; ipcrm -S {$ikey}";
$last_line = exec($cmd, $output, $retval);
} while ($retry_times-- > 0);
if (!sem_acquire($sem)) {
return false;
}
$next_value = false;
if (shm_has_var($shm, $ikey)) {
shm_put_var($shm, $ikey, $next_value = shm_get_var($shm, $ikey) + 1);
} else {
shm_put_var($shm, $ikey, $next_value = 1);
}
$shm && shm_detach($shm);
$sem && sem_release($sem);
return $next_value;
}
示例15: Explain
function Explain($sql, $partial = false)
{
$save = $this->conn->LogSQL(false);
if ($partial) {
$sqlq = $this->conn->qstr($sql . '%');
$arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like {$sqlq}");
if ($arr) {
foreach ($arr as $row) {
$sql = reset($row);
if (crc32($sql) == $partial) {
break;
}
}
}
}
$sql = str_replace('?', "''", $sql);
$s = '<p><b>Explain</b>: ' . htmlspecialchars($sql) . '</p>';
$rs = $this->conn->Execute('EXPLAIN ' . $sql);
$this->conn->LogSQL($save);
$s .= '<pre>';
if ($rs) {
while (!$rs->EOF) {
$s .= reset($rs->fields) . "\n";
$rs->MoveNext();
}
}
$s .= '</pre>';
$s .= $this->Tracer($sql, $partial);
return $s;
}