国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ??? ?? PHP ???? PHP? ??? memcached ??? ???

PHP? ??? memcached ??? ???

Jul 25, 2016 am 08:43 AM

  1. /*
  2. * memcache ??? ???
  3. * ?? ????? ?? ?? ?? ? ?? ??
  4. * ?? ?? ??, AB ?? ?? ??
  5. * @author guoyu
  6. * @create on 9:25 2014-9-28
  7. * @qq ???? ??? : 136112330
  8. *
  9. * @?:
  10. * $obj = new memcacheQueue('duilie');
  11. * $obj->add('1asdf')
  12. * $obj->getQueueLength(); read(11); * $obj->get(8);
  13. */
  14. class memcacheQueue{
  15. public static $client
  16. public $access; //? ???? ?? ??
  17. private $currentSide; //?? ??? ? ?: A/B
  18. private $lastSide; //?? ??? ? ?: A/ B
  19. private $sideAHead; //A?? ? ?? ?
  20. private $sideATail; //A?? ??? ?
  21. private $sideBHead; //B?? ? ?? ?
  22. private $sideBTail; // B?? ??? ?
  23. private $currentHead; //?? ?? ? ?? ?
  24. private $currentTail; //?? ?? ??? ?
  25. private $lastHead; > private $ lastTail; //?? ??? ???? ?? ?
  26. private $expire; //?? ??, ?, 1~2592000, ? 30? ???? ???? ??? ?????.
  27. private $ sleepTime; //?? ?? ?? ??, ?????
  28. private $queueName; //? ??, ?? ?
  29. private $retryNum; //??? ??, = 10 * ???? ??? ?
  30. const MAXNUM = 2000; //(??) ?? ??? ?, ?? ??? 10K???.
  31. const HEAD_KEY = '_lkkQueueHead_' // ??? ?? ?
  32. const TAIL_KEY = '_lkkQueueTail_' // ??? ?? ?
  33. const VALU_KEY = '_lkkQueueValu_'; // ??? ? ?
  34. const LOCK_KEY = '_lkkQueueLock_' // ??? ?? ?
  35. const SIDE_KEY = '_lkkQueueSide_' // ?? ?? ?
  36. /*
  37. * ???
  38. * @param [config] ?? memcache ?? ????
  39. * @param [queueName] ??? ??? ??
  40. * @param [expire] ??? ?? ??
  41. * @return NULL
  42. */
  43. ?? ?? __construct($queueName ='',$expire='',$config =''){
  44. if(empty($config)){
  45. self::$client = memcache_pconnect('localhost',11211 );
  46. }elseif(is_array($config)){//array('host'=>'127.0.0.1','port'=> ;'11211')
  47. self::$client = memcache_pconnect($config['host'],$config['port'])
  48. }elseif(is_string($config)){//"127.0 .0.1:11211"
  49. $tmp = ??(' :',$config);
  50. $conf['host'] = isset($tmp[0]) ? $tmp[0] : '127.0. 0.1';
  51. $conf['port'] = isset($tmp[1]) ? $tmp[1] : '11211'
  52. self::$client($conf['host') ],$conf['port']);
  53. }
  54. if(!self::$client) return false
  55. ignore_user_abort(TRUE);//????? ??? ???? ??? ?????. ??
  56. set_time_limit(0);//???? ?? ?? ??
  57. $this->access = false
  58. $this->sleepTime = 1000; = (?? ??($expire) && $expire!=0) ? 3600 : (int)$expire;
  59. $this->expire = $expire; ??> $this->retryNum = 10000;
  60. $side = memcache_add(self::$client, $queueName . self::SIDE_KEY, 'A',false, $expire)
  61. $ this->getHeadNTail($queueName);
  62. if (!isset($this->sideAHead) || ?? ??($this->sideAHead)) $this->sideAHead = 0; (!isset($this->sideATail) || ?? ?? ($this->sideATail)) $this->sideATail = 0
  63. if(!isset($this->sideBHead) || ?? ?? ($this->sideBHead)) $this-> sideBHead = 0
  64. if(!isset($this->sideBHead) || ?? ??($this->sideBHead)) $this-> sideBHead = 0
  65. }
  66. /*
  67. * 獲取隊(duì)列首尾值
  68. * @param [queueName] string 隊(duì)列name稱
  69. * @return NULL
  70. */
  71. ??? ?? getHeadNTail($queueName) {
  72. $this->sideAHead = (int)memcache_get(self::$client, $queueName.'A'.self::HEAD_KEY);
  73. $this->sideATail = (int)memcache_get(self::$client, $queueName.'A'.self::TAIL_KEY);
  74. $this->sideBHead = (int)memcache_get(self::$client, $queueName.'B'.self::HEAD_KEY);
  75. $this->sideBTail = (int)memcache_get(self::$client, $queueName.'B'.self::TAIL_KEY);
  76. }
  77. /*
  78. * 獲取當(dāng)前輪值的隊(duì)列?
  79. * @return string 隊(duì)列??稱
  80. */
  81. ?? ?? getCurrentSide(){
  82. $ currentSide = memcache_get(self::$client, $this->queueName . self::SIDE_KEY);
  83. if($currentSide == 'A'){
  84. $this->currentSide = 'A';
  85. $this->lastSide = 'B';
  86. $this->currentHead = $this->sideAHead;
  87. $this->currentTail = $this->sideATail;
  88. $this->lastHead = $this->sideBHead;
  89. $this->lastTail = $this->sideBTail;
  90. }else{
  91. $this->currentSide = 'B';
  92. $this->lastSide = 'A';
  93. $this->currentHead = $this->sideBHead;
  94. $this->currentTail = $this->sideBTail;
  95. $this->lastHead = $this->sideAHead;
  96. $this->lastTail = $this->sideATail;
  97. }
  98. return $this->currentSide;
  99. }
  100. /*
  101. * 隊(duì)列加鎖
  102. * @return boolean
  103. */
  104. ??? ?? getLock(){
  105. if($this-> access === false){
  106. while(!memcache_add(self::$client, $this->queueName .self::LOCK_KEY, 1, false, $this->expire) ){
  107. usleep ($this->sleepTime);
  108. @$i ;
  109. if($i > $this->retryNum){//嘗試等待N次
  110. return false;
  111. ??;
  112. }
  113. }
  114. return $this->access = true;
  115. }
  116. false? ?????.
  117. }
  118. /*
  119. * 隊(duì)列解鎖
  120. * @return NULL
  121. */
  122. ??? ?? unLock(){
  123. memcache_delete(self::$client, $this->queueName .self::LOCK_KEY);
  124. $this->access = false;
  125. }
  126. /*
  127. * 添加數(shù)據(jù)
  128. * @param [data] 要存儲(chǔ)的值
  129. * @return boolean
  130. */
  131. ?? ?? add( $data){
  132. $result = false;
  133. if(!$this->getLock()){
  134. return $result;
  135. }
  136. $this->getHeadNTail($this->queueName);
  137. $this->getCurrentSide();
  138. if($this->isFull()){
  139. $this->unLock();
  140. false? ?????.
  141. }
  142. if($this->currentTail < self::MAXNUM){
  143. $value_key = $this->queueName .$this->currentSide . ??::VALU_KEY . $this->currentTail;
  144. if(memcache_add(self::$client, $value_key, $data, false, $this->expire)){
  145. $this->changeTail();
  146. $?? = ?;
  147. }
  148. }else{//當(dāng)前隊(duì)列已滿,更換輪值面
  149. $this->unLock();
  150. $this->changeCurrentSide();
  151. return $this->add($data);
  152. }
  153. $this->unLock();
  154. $?? ??;
  155. }
  156. /*
  157. * 取出數(shù)據(jù)
  158. * @param [length] int 數(shù)據(jù)的長titude
  159. * @return ??
  160. */
  161. ?? ?? get( $length=0){
  162. if(!is_numeric($length)) return false;
  163. if(empty($length)) $length = self::MAXNUM * 2;//默認(rèn)讀取所有
  164. if(!$this->getLock()) return false;
  165. if($this->isEmpty()){
  166. $this->unLock();
  167. false? ?????.
  168. }
  169. $keyArray = $this->getKeyArray($length);
  170. $lastKey = $keyArray['lastKey'];
  171. $currentKey = $keyArray['currentKey'];
  172. $keys = $keyArray['keys'];
  173. $this->changeHead($this->lastSide,$lastKey);
  174. $this->changeHead($this->currentSide,$currentKey);
  175. $data = @memcache_get(self::$client, $keys);
  176. foreach($keys as $v){//??后刪除
  177. @memcache_delete(self::$client, $v, 0);
  178. }
  179. $this->unLock();
  180. $data? ?????.
  181. }
  182. /*
  183. * 讀取數(shù)據(jù)
  184. * @param [length] int 數(shù)據(jù)的長島
  185. * @return ??
  186. */
  187. ?? ?? ?? ($length=0){
  188. if(!is_numeric($length)) return false;
  189. if(empty($length)) $length = self::MAXNUM * 2;//默認(rèn)讀取所有
  190. $keyArray = $this->getKeyArray($length);
  191. $data = @memcache_get(self::$client, $keyArray['keys']);
  192. $data? ?????.
  193. }
  194. /*
  195. * 獲取隊(duì)列某段長島的key數(shù)組
  196. * @param [length] int 隊(duì)列長島
  197. * @return ??
  198. */
  199. ?? ?? getKeyArray($length){
  200. $result = array('keys'=>array(),'lastKey'=>array(),'currentKey'=>array());
  201. $this->getHeadNTail($this->queueName);
  202. $this->getCurrentSide();
  203. if(empty($length)) return $result;
  204. //?? ?
  205. $i = $result['lastKey'] = 0;
  206. for($i=0;$i<$length;$i ){
  207. $result['lastKey'] = $this->lastHead $i;
  208. if($result['lastKey'] >= $this->lastTail) break;
  209. $result['keys'][] = $this->queueName .$this->lastSide . ??::VALU_KEY . $result['lastKey'];
  210. }
  211. //再取當(dāng)??? ?
  212. $j = $length - $i;
  213. $k = $result['currentKey'] = 0;
  214. for($k=0;$k<$j;$k ){
  215. $result['currentKey'] = $this->currentHead $k;
  216. if($result['currentKey'] >= $this->currentTail) break;
  217. $result['keys'][] = $this->queueName .$this->currentSide . ??::VALU_KEY . $result['???'];
  218. }
  219. $result ??;
  220. }
  221. /*
  222. * 更新當(dāng)前輪值?隊(duì)列尾?值
  223. * @return NULL
  224. */
  225. ??? ??changeTail(){
  226. $tail_key = $this->queueName .$this->currentSide . ??::TAIL_KEY;
  227. memcache_add(self::$client, $tail_key, 0,false, $this->expire);//如果沒有,則插入;有則false;
  228. //memcache_increment(self::$client, $tail_key, 1);//隊(duì)列尾 1
  229. $v = memcache_get(self::$client, $tail_key) 1;
  230. memcache_set(self::$client, $tail_key,$v,false,$this->expire);
  231. }
  232. /*
  233. * 更新隊(duì)列首?值
  234. * @param [side] string 要更新的面
  235. * @param [headValue] int 隊(duì)列首的值
  236. * @return NULL
  237. */
  238. ??? ??changeHead($side,$headValue){
  239. if($headValue < 1) return false;
  240. $head_key = $this->queueName .$side . ??::HEAD_KEY;
  241. $tail_key = $this->queueName .$side . ??::TAIL_KEY;
  242. $sideTail = memcache_get(self::$client, $tail_key);
  243. if($headValue < $sideTail){
  244. memcache_set(self::$client, $head_key,$headValue 1,false,$this->expire);
  245. }elseif($headValue >= $sideTail){
  246. $this->resetSide($side);
  247. }
  248. }
  249. /*
  250. * ? ??? ??
  251. * @return NULL
  252. */
  253. ?? ?? ResetSide($side){
  254. $head_key = $this->queueName .$side . ??::HEAD_KEY;
  255. $tail_key = $this->queueName .$side . ??::TAIL_KEY;
  256. memcache_set(self::$client, $head_key,0,false,$this->expire);
  257. memcache_set(self::$client, $tail_key,0,false,$this->expire);
  258. }
  259. /*
  260. * 改變當(dāng)前輪值隊(duì)列?
  261. * @return string
  262. */
  263. private functionchangeCurrentSide(){
  264. $currentSide = memcache_get(self::$ ?????, $this->queueName .self::SIDE_KEY);
  265. if($currentSide == 'A'){
  266. memcache_set(self::$client, $this->queueName . self::SIDE_KEY,'B',false,$this->expire) ;
  267. $this->currentSide = 'B';
  268. }else{
  269. memcache_set(self::$client, $this->queueName . self::SIDE_KEY,'A',false,$this->expire);
  270. $this->currentSide = 'A';
  271. }
  272. return $this->currentSide;
  273. }
  274. /*
  275. * 檢查當(dāng)前隊(duì)列是否已滿
  276. * @return boolean
  277. */
  278. public function isFull(){
  279. $result = false ;
  280. if($this->sideATail == self::MAXNUM && $this->sideBTail == self::MAXNUM){
  281. $result = true;
  282. }
  283. $result ??;
  284. }
  285. /*
  286. * 檢查當(dāng)前隊(duì)列是否為空
  287. * @return boolean
  288. */
  289. public function isEmpty(){
  290. $result = true ;
  291. if($this->sideATail > 0 || $this->sideBTail > 0){
  292. $result = false;
  293. }
  294. $result ??;
  295. }
  296. /*
  297. * 獲取當(dāng)前隊(duì)列? ??
  298. * 該長島為理論長島,某些元素由于過期失效而丟失,真實(shí)?? 小于或等于該長島
  299. * @return int
  300. */
  301. ?? ?? getQueueLength(){
  302. $this->getHeadNTail($this->queueName);
  303. $this->getCurrentSide();
  304. $sideALength = $this->sideATail - $this->sideAHead;
  305. $sideBLength = $this->sideBTail - $this->sideBHead;
  306. $result = $sideALength $sideBLength;
  307. $result? ?????.
  308. }
  309. /*
  310. * 清空當(dāng)前隊(duì)列數(shù)據(jù),僅保留HEAD_KEY、TAIL_KEY、SIDE_KEY??key
  311. * @return boolean
  312. */
  313. ?? ?? ???( ){
  314. if(!$this->getLock()) return false;
  315. for($i=0;$i @memcache_delete(self::$client, $this->queueName.'A'.self::VALU_KEY . $i, 0);
  316. @memcache_delete(self::$client, $this->queueName.'B'.self::VALU_KEY .$i, 0);
  317. }
  318. $this->unLock();
  319. $this->resetSide('A');
  320. $this->resetSide('B');
  321. true? ?????.
  322. }
  323. /*
  324. * 清除所有memcache緩存數(shù)據(jù)
  325. * @return NULL
  326. */
  327. ?? ?? memFlush(){
  328. memcache_flush(self:: $?????);
  329. }
  330. }
復(fù)??碼

PHP, ???


? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
PHP ?? ??? ??????? PHP ?? ??? ??????? Jul 17, 2025 am 04:16 AM

PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.

PHP?? ?? ???? ???? ???? ??? ?????? PHP?? ?? ???? ???? ???? ??? ?????? Jul 08, 2025 am 02:37 AM

PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.

PHP?? ?? ?? PHP?? ?? ?? Jul 18, 2025 am 04:57 AM

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.

PHP?? ???? ??? ?????? PHP?? ???? ??? ?????? Jul 11, 2025 am 03:12 AM

Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2

PHP ?? ?? ? PHP ?? ?? ? Jul 18, 2025 am 04:51 AM

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

?? PHP : ??? ??? ?? PHP : ??? ??? Jul 18, 2025 am 04:54 AM

tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled

?? PHP ?? ??? ?? PHP ?? ??? Jul 18, 2025 am 04:52 AM

toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2

PHP?? ??? ? ???? ??? ????? ?? PHP?? ??? ? ???? ??? ????? ?? Jul 12, 2025 am 03:15 AM

PHP??? ???? ??? ?? ?? ????? ???? ??? ?? ??? ??? ?? ? ??? ??? ???? ?????. ???? 0?? ???? ?? ??? ???? ? ?? ???? ?? ?? ? ? ????. MB_SUBSTR? ?? ??? ??? ???????. ? : $ str = "hello"; echo $ str [0]; ?? H; ??? MB_SUBSTR ($ str, 1,1)? ?? ??? ??? ??? ??????. ?? ???????? ???? ??? ???? ?? ???? ?? ?? ???? ?????? ??? ????? ?? ??? ?? ??? ???? ???? ?? ????.

See all articles