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


PHP Q_Config::setOnServer方法代码示例

本文整理汇总了PHP中Q_Config::setOnServer方法的典型用法代码示例。如果您正苦于以下问题:PHP Q_Config::setOnServer方法的具体用法?PHP Q_Config::setOnServer怎么用?PHP Q_Config::setOnServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Q_Config的用法示例。


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

示例1: Q_Config_post

/**
 * Handle different tasks related to Q config
 */
function Q_Config_post()
{
    switch (isset($_REQUEST['Q/method']) ? $_REQUEST['Q/method'] : null) {
        case 'clear':
            if (!isset($_REQUEST['filename'])) {
                throw new Q_Exception("'filename' is not defined in 'clear', 'Q/config' handler");
            } else {
                $filename = $_REQUEST['filename'];
            }
            if (!isset($_REQUEST['args'])) {
                throw new Q_Exception("'args' is not defined in 'clear', 'Q/config' handler");
            } else {
                $args = $_REQUEST['args'];
            }
            if (!isset($_REQUEST['noSave'])) {
                throw new Q_Exception("'noSave' is not defined in 'clear', 'Q/config' handler");
            } else {
                $noSave = $_REQUEST['noSave'];
            }
            Q_Config::$cache = Q_Config::clearOnServer($filename, $args, $noSave);
            break;
        case 'set':
            if (!isset($_REQUEST['filename'])) {
                throw new Q_Exception("'filename' is not defined in 'set', 'Q/config' handler");
            } else {
                $filename = $_REQUEST['filename'];
            }
            if (!isset($_REQUEST['data'])) {
                throw new Q_Exception("'data' is not defined in 'set', 'Q/config' handler");
            } else {
                $data = $_REQUEST['data'];
            }
            if (!isset($_REQUEST['clear'])) {
                throw new Q_Exception("'clear' is not defined in 'set', 'Q/config' handler");
            } else {
                $clear = $_REQUEST['clear'];
            }
            Q_Config::$cache = Q_Config::setOnServer($filename, $data, $clear);
            break;
        case 'get':
            if (!isset($_REQUEST['filename'])) {
                throw new Q_Exception("'filename' is not defined in 'put', 'Q/config' handler");
            } else {
                $filename = $_REQUEST['filename'];
            }
            Q_Config::$cache = Q_Config::getFromServer($filename);
            break;
        default:
            throw new Q_Exception("Unknown 'Q/method' in 'Q/config' handler");
            break;
    }
}
开发者ID:dmitriz,项目名称:Platform,代码行数:55,代码来源:post.php

示例2: split


//.........这里部分代码省略.........
         $order[] = "CAST({$hash}({$field}) AS CHAR({$len}))";
     }
     // if any field uses 'normalize' hash
     // the original shard shall have MySQL NORMALIZE() function defined
     // MySQL version of NORMALIZE handles only 255 chars and does not add md5 hash
     // (see Db_Utils::normalize)
     if ($normalize) {
         try {
             $pdo->exec("DROP FUNCTION IF EXISTS NORMALIZE;");
             $pdo->exec("CREATE FUNCTION NORMALIZE(s CHAR(255))\n\t\t\t\t\t\tRETURNS CHAR(255) DETERMINISTIC\n\t\t\t\t\t\tBEGIN\n\t\t\t\t\t    \tDECLARE res CHAR(255) DEFAULT '';\n\t\t\t\t\t  \t\tDECLARE t CHAR(1);\n\t\t\t\t\t    \tWHILE LENGTH(s) > 0 DO\n\t\t\t\t\t        \tSET t = LOWER(LEFT(s, 1));\n\t\t\t\t\t    \t    SET s = SUBSTRING(s FROM 2);\n\t\t\t\t\t        \tIF t REGEXP '[^A-Za-z0-9]' THEN\n\t\t\t\t\t            \tSET t = '_';\n\t\t\t\t\t        \tEND IF;\n\t\t\t\t\t        \tSET res = CONCAT(res, t);\n\t\t\t\t\t    \tEND WHILE;\n\t\t\t\t\t    \tRETURN res;\n\t\t\t\t\t\tEND");
         } catch (Exception $e) {
             //echo "ERROR: {$e->getMessage()}\n";
             echo "Please, make sure that db user for shard '{$shard_name}' has 'CREATE ROUTINE' permission\n";
             return false;
         }
     }
     $order = join(', ', $order);
     $group = join(', ', $group);
     $where = "(STRCMP(CONCAT({$order}), '{$lower}') >= 0)" . (isset($upper) ? " AND (STRCMP(CONCAT({$order}), '{$upper}') < 0)" : "");
     $count = reset($pdo->query("SELECT COUNT(*) FROM {$shard_table} WHERE {$where}")->fetchAll(PDO::FETCH_NUM));
     if (empty($count)) {
         echo "Failed to connect to shard '{$shard_name}'\n";
         return false;
     }
     $count = reset($count);
     if ($count == 0) {
         echo "Cannot split empty shard!\n";
         return false;
     }
     // if only one new shard provided script will copy data and cnange config
     if (($num_shards = count($parts)) < 1) {
         echo "Please, provide at least one new shard";
         return false;
     }
     $break = round($count / $num_shards);
     // if split config is not mapped and current config is mapped we shall convert split
     //  config to mapped
     $new_partition = $mapped || $split_mapped ? array($shard => $split_mapped ? reset(array_keys($parts)) : $shard) : array($shard);
     $new_shards = array($split_mapped ? reset(array_keys($parts)) : $shard => reset($parts));
     $i = 0;
     foreach (array_slice($parts, 1) as $name => $dsn) {
         $offset = $break * ++$i;
         $split = reset($pdo->query("SELECT {$group} FROM {$shard_table} WHERE {$where} ORDER BY {$order} LIMIT {$offset}, 1")->fetchAll(PDO::FETCH_ASSOC));
         foreach ($fields as $field => $hash) {
             $split[$field] = Db_Query::hashed($split[$field], $hash);
         }
         $split = join('.', $split);
         if ($mapped || $split_mapped) {
             $new_partition[$split] = $split_mapped ? $name : $split;
         } else {
             $new_partition[] = $split;
         }
         $new_shards[$new_name = $split_mapped ? $name : $split] = $dsn;
         if (Q_Config::get('Db', 'connections', $connection, 'shards', $new_name, false)) {
             echo "WARNING!!! Shard already exists: '{$new_name}'\n";
         }
     }
     Q_Config::merge(array('Db' => array('connections' => array($connection => array("shards" => $new_shards)))));
     // if split config is mapped and current config is not we shall convert app config to mapped
     if ($split_mapped && !$mapped) {
         $partition = array();
         foreach ($points as $point) {
             $partition[$point] = $point;
         }
         Q_Config::set('Db', 'connections', $connection, 'indexes', $table, 'partition', $partition);
         $mapped = true;
     }
     // TODO: verify if new shards sizes are approx. equal
     // Verify versions of existing shards and
     // Install pligin schema to new shards
     Q_Plugin::installSchema(Q_PLUGINS_DIR . DS . $plugin, $plugin, 'plugin', $connection, array('sql' => array($connection => array('enabled' => true))));
     // make sure 'upcoming' config is loaded
     $configFiles = Q_Config::get('Q', 'configFiles', array());
     // 'local/Q/bootstrap.json' should be loaded already but we'll better check
     if (!in_array('Q/config/bootstrap.json', $configFiles)) {
         echo "Config file 'Q/config/bootstrap.json' shall be loaded via 'Q/configFiles key'\non every Q server - check 'platform/config/Q.json'\n";
         return false;
     }
     $upcoming_file = Q_Config::get('Q', 'internal', 'sharding', 'upcoming', 'Db/config/upcoming.json');
     //if (!unlink ($upcoming_file)) {
     //	echo "Please, manually remove file '$upcoming_file' and start this script again.\n";
     //	return false;
     //}
     if (!in_array($upcoming_file, $configFiles)) {
         // add upcoming.json to config
         if (!Q_Config::setOnServer('Q/config/bootstrap.json', array('Q' => array('configFiles' => array($upcoming_file))))) {
             echo "Failed to update 'local/Q/bootstrap.json'\n";
             return false;
         }
     }
     // Now after some short time all workers (php and node) will be ready for splitting
     // We'll let node server to wait necessary amount of time.
     $res = Q_Utils::queryInternal('Db/Shards', array('Q/method' => 'split', 'shard' => $shard_name, 'shards' => Q::json_encode($new_shards), 'part' => $shard, 'table' => $table, 'dbTable' => $shard_table, 'class' => $class, 'plugin' => $plugin, 'connection' => $connection, 'where' => $where, 'parts' => Q::json_encode(array('partition' => $new_partition, 'fields' => $fields))), $node);
     if ($res) {
         echo "Split process for shard '{$shard_name}' ({$shard}) has started\nPlease, monitor node.js console for important messages and process status\n";
         return true;
     }
     echo "Failed to start split process at node server\n";
     return false;
 }
开发者ID:AndreyTepaykin,项目名称:Platform,代码行数:101,代码来源:Utils.php


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