锟斤拷锟斤拷涌锟斤拷峁┮伙拷锟斤拷锟斤拷锟斤拷锟斤拷姆锟绞斤拷锟斤拷锟斤拷锟斤拷锟秸癸拷涌凇锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷示锟斤拷使锟矫讹拷锟襟化接匡拷实锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷印锟斤拷锟斤拷锟斤拷拥锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷示"锟斤拷锟斤拷锟斤拷锟斤拷效!"锟斤拷为锟斤拷 PHP 锟斤拷锟斤拷锟侥憋拷锟斤拷 $counter_three 锟斤拷锟角讹拷锟斤拷木锟斤拷锟斤拷锟较拷锟斤拷猓拷锟斤拷锟斤拷锟饺伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟秸故撅拷硕锟斤拷锟斤拷锟斤拷锟秸癸拷卸锟斤拷锟斤拷 Counter 锟斤拷锟斤拷锟洁,锟斤拷锟斤拷实锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫凤拷锟斤拷锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷
Example #1 "counter" 锟侥讹拷锟襟化接匡拷
<?php
class MyCounter extends Counter
{
public function printCounterInfo() {
printf("锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为 '%s'锟斤拷锟斤拷%s锟斤拷锟叫持久伙拷锟斤拷锟戒当前值为 %d.\n",
$this->getMeta(COUNTER_META_NAME),
$this->getMeta(COUNTER_META_IS_PERSISTENT) ? '' : '锟斤拷',
$this->value);
}
}
Counter::setCounterClass("MyCounter");
if (($counter_one = Counter::getNamed("one")) === NULL) {
$counter_one = new Counter("one", 0, COUNTER_FLAG_PERSIST);
}
$counter_one->bumpValue(2); // 锟斤拷锟斤拷锟斤拷直锟斤拷 "set" 值
$counter_two = new Counter("two", 5);
$counter_three = Counter::getNamed("three");
$counter_four = new Counter("four", 2, COUNTER_FLAG_PERSIST | COUNTER_FLAG_SAVE | COUNTER_FLAG_NO_OVERWRITE);
$counter_four->bumpValue(1);
$counter_one->printCounterInfo();
$counter_two->printCounterInfo();
$counter_three->printCounterInfo();
$counter_four->printCounterInfo();
?>