function process_request()
{
    $item_name = isset($_POST['item_name']) ? $_POST['item_name'] : null;
    $item_price = isset($_POST['item_price']) ? $_POST['item_price'] : null;
    $item_description = isset($_POST['item_description']) ? $_POST['item_description'] : null;
    $item_img = isset($_POST['item_img']) ? $_POST['item_img'] : null;
    if (is_null($item_name)) {
        die;
    } else {
        $item_name = htmlspecialchars(trim($item_name));
        if ($item_name === '') {
            die;
        }
    }
    if (is_null($item_price) || !preg_match("/^\\d+([.,]\\d{1,2})?\$/", $item_price)) {
        die;
    }
    $item_price = str_replace(',', '.', $item_price);
    if (is_null($item_description)) {
        die;
    } else {
        $item_description = htmlspecialchars(trim($item_description));
    }
    if (is_null($item_img)) {
        $item_img = "Null";
    }
    $id = db_insert_item($item_name, $item_description, $item_price, $item_img);
    $mc_handler = memcache_connect('localhost');
    if (memcache_get($mc_handler, 'total_rows') !== false) {
        memcache_increment($mc_handler, 'total_rows');
        pagination_rebuild_ids($mc_handler, $id);
        pagination_rebuild_prices($mc_handler, $item_price);
    }
    header('Location: /view_item.php?id=' . $id);
}
Exemple #2
0
function SaeMemcacheIncrement($key, $value)
{
    //如果长度超出,则取末尾的234位
    if (strlen($key) > 234) {
        $key = substr($key, -234);
    }
    $mmc = memcache_init();
    if ($mmc == false) {
        return false;
    } else {
        return memcache_increment($mmc, $key, $value);
    }
    //如果指定的key对应的元素不是数值类型并且不能被转换为数值, 会将此值修改为value
    //memcache_increment()不会在key对应元素不存在时创建元素
}
Exemple #3
0
function process_request()
{
    $item_name = isset($_POST['item_name']) ? $_POST['item_name'] : null;
    $item_price = isset($_POST['item_price']) ? $_POST['item_price'] : null;
    $item_description = isset($_POST['item_description']) ? $_POST['item_description'] : null;
    $item_img = isset($_POST['item_img']) ? $_POST['item_img'] : null;
    $errors = [];
    if (is_null($item_name)) {
        $errors[] = 'Non-empty name required';
    } else {
        $item_name = htmlspecialchars(trim($item_name));
        if ($item_name === '') {
            $errors[] = 'Non-empty name required';
        }
    }
    if (is_null($item_price) || !preg_match("/^\\d+([.,]\\d{1,2})?\$/", $item_price)) {
        $errors[] = 'Incorrect price number';
    }
    if (is_null($item_description)) {
        $errors[] = 'Incorrect description';
    } else {
        $item_description = htmlspecialchars(trim($item_description));
    }
    if (!empty($errors)) {
        api_echo_as_json($errors, 'errors', RESPONSE_STATUS_FAIL);
        return;
    }
    $item_price = str_replace(',', '.', $item_price);
    if (is_null($item_img)) {
        $item_img = "Null";
    }
    db_insert_item($item_name, $item_description, $item_price, $item_img);
    $mc_handler = memcache_connect('localhost');
    if (memcache_get($mc_handler, 'total_rows') !== false) {
        memcache_increment($mc_handler, 'total_rows');
    }
    api_echo_as_json('Item created', 'msg');
}
Exemple #4
0
 public function testIncrementNonExistingValue()
 {
     $memcache = new Memcache();
     $request = new MemcacheIncrementRequest();
     $request->setKey("key");
     $request->setDelta(5);
     $response = new MemcacheIncrementResponse();
     $this->apiProxyMock->expectCall('memcache', 'Increment', $request, $response);
     $this->assertFalse(memcache_increment($memcache, "key", 5));
     $this->apiProxyMock->verify();
 }
Exemple #5
0
function MCache_increment($mcConnect, $key, $value)
{
    return memcache_increment($mcConnect, $key, $value);
}
Exemple #6
0
/**
 * @see http://php.net/manual/ru/memcache.increment.php
 *
 * @param array &$Memcached объект мемкеша
 * @param string $key ключ инкремента
 * @param int   $value стартовое значение
 *
 * @return int|bool новое значение ключа или false при ошибке
 */
function increment(array &$Memcached, $key, $value = 1)
{
    return memcache_increment(getMemcacheObject($Memcached), $key, $value);
}
Exemple #7
0
 public function increment($key = '', $increment = 1)
 {
     return memcache_increment($key, $increment);
 }
Exemple #8
0
 /**
  * Increment item's value
  *
  * @param	string	$ns			Key namespace (read from config)
  * @param	string	$key		Key name
  * @param	int		$value 		Increment the item by value. Optional and defaults to 1.
  * @return	mixed				New item's value on success or FALSE on failure.
  */
 public function inc($ns, $key, $val = 1)
 {
     $this->_checkNs($ns);
     $key = $this->_keyNs[$ns]['value'] . ':' . $key;
     return memcache_increment($this->_conn($ns), $key, $val);
 }
Exemple #9
0
 /**
  * Increment the value of an item in the cache.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return int|bool
  */
 public function increment($key, $value = 1)
 {
     return memcache_increment($this->memcache, $key, $value);
 }
Exemple #10
0
 function inc($name, $step = 1)
 {
     return memcache_increment($this->_mamcache, $this->prefix . $name, $step);
 }
Exemple #11
0
 public static function inc($key)
 {
     return \memcache_increment(self::$connection, $key);
 }
Exemple #12
0
            $mailprefix[] = $monitorPhone['mailprefix'];
        }
        //短信接口
        $url = 'http://202.108.35.62/serverguard/SendV2.php?user=general&password=nbaa8a2a1d5b981deacb8c1e2general&phone=' . urlencode(implode(',', $phone)) . '&msg=' . urlencode($messageSend) . '&level=' . urlencode($submodule['level']);
        _http_get($url, array('timeout' => 1), $info);
        $url = 'http://i.alarm.mix.sina.com.cn/?s=client&a=message&format=json&to=' . urlencode(implode(',', $mailprefix)) . '&content=' . urlencode($messageSend) . '&level=' . urlencode($submodule['level']);
        _http_get($url, array('timeout' => 1), $info);
        memcache_delete($mc, $smsMsgKey);
        echo 'sms';
        //exit('sms');
    }
}
$mailMsgKey = implode('|', array('mail_msg', $submodule['id']));
$mailMsgInitRes = memcache_add($mc, $mailMsgKey, 1, false, 3600);
if ($mailMsgInitRes === false) {
    $mailMsgCount = memcache_increment($mc, $mailMsgKey, 1);
} else {
    $mailMsgCount = 1;
}
echo $mailMsgCount;
$mailWarningKey = implode('|', array('mail', $submodule['id']));
if ($mailMsgCount >= $submodule['mail_limit'] && $submodule['mail_status']) {
    //sendmail
    $mailLock = memcache_add($mc, $mailWarningKey, 1, false, 600);
    if ($mailLock === true) {
        $arr = $matches = array();
        preg_match("/^SELECTED:\\[(.*)\\]\$/", $project['monitors'], $matches);
        $str = str_replace('\'', '"', "[" . $matches[1] . "]");
        $projectUids = json_decode($str, true);
        $arr = $matches = array();
        if (!empty($submodule['monitors'])) {
Exemple #13
0
function increment_var($var, $value)
{
    $memcached = __memcache();
    if ($value > 0) {
        $memcached = memcache_increment($memcached, $var, $value);
        if ($memcached) {
            echo "Variable {$var} was incremented with {$value}";
        }
    }
}