PHPÖеÄʵÏÖRegistryģʽ¹ý³ÌÖеÄÁìÎò
<?php
/*
Singleton && Registry Design Pattern Implementation
*/
class Registry {
private $_store = array();
public function getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] = new Registry;
}
return $instance[0];
}
public function &get($key){
if($this->isValid($key)){
return $this->_store[$key];
}
}
public function set($key, $object){
$this->_store[$key] = &$object;
}
public function isValid($key){
return array_key_exists($key,$this->_store);
}
}
?>
Test Case:
<?php
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once 'Registry.php';
class RegistryTestCase extends UnitTestCase{
function testRegistryIsSingleton(){
$this->assertIsA($reg = Registry::getInstance(), 'Registry');
$this->assertReference($reg, Registry::getInstance());
}
function testEmptyRegistryKeyIsReturnNull(){
$reg = Registry::getInstance();
$this->assertNull($reg->get('key'));
}
function testEmptyRegistryKeyIsInvalid(){
$reg = Registry::getInstance();
$this->assertFalse($reg->get('key'));
}
function testSetRegistryKeyBecomesValid(){
$reg = Registry::getInstance();
$test_value = 'something';
settype($test_value, 'Object');
$reg->set('key', $test_value);
$this->assertTrue($reg->isValid('key'));
}
function testRegistryValueIsReference(){
$reg = Registry::getInstance();
$test_value = 'something';
$reg->set('key', $test_value);
Ïà¹ØÎĵµ£º
//ת»»ÎªUNIXʱ¼ä´Á
function strtotimestamp(datestr)
{
var new_str = datestr.replace(/:/g,"-");
new_str = new_str.replace(/ /g,"-");
var arr = new_str.split("-");
var datum = new Date(Date. ......
¡¡¡¡ÎÒ¿ª·¢µÄСվ£ºhttp://www.asprain.com£¬»¶Ó¹ÛĦ¡¢ÌåÑ飡
¡¡¡¡°¡£¬½ñÌì¿´µ½ºÜ¶àÈË˵ÎÒÂîPHP³ÌÐòÔ±ÊÇÔÚ³´×÷£¬Ä¿µÄÊÇÍÆ¹ãÎÒµÄÂÛ̳³ÌÐò¡£»°Ëµ£¬ËäÈ»ÎÒ֮ǰһֱºÜÏëÏë°ì·¨Ìá¸ß×Ô¼ºÐ´µÄÄǸö³ÌÐòµÄÖªÃû¶È¡£ÎÒ°ÑÎÒµÄСվ½éÉܸøÎÒµÄËùÓеĺÃÓÑ£¬ÇëËûÃǿڿÚÏà´«¡£µ«ÊÇÎÒȷʵдÕâÆªÎÄÕÂÊÇûÓг´×÷Ä¿µÄµÄ¡£ÔÒòºÜ¼òµ¥£ºÎÒÐ ......
PDOÊÇÒ»¸ö“Êý¾Ý¿â·ÃÎʳéÏó²ã”£¬×÷ÓÃÊÇͳһ¸÷ÖÖÊý¾Ý¿âµÄ·ÃÎʽӿڣ¬ÓëmysqlºÍmysqliµÄº¯Êý¿âÏà±È£¬PDOÈÿçÊý¾Ý¿âµÄʹÓøü¾ßÓÐÇ׺ÍÁ¦£»ÓëADODBºÍMDB2Ïà±È£¬PDO¸ü¸ßЧ¡£Ä¿Ç°¶øÑÔ£¬ÊµÏÖ“Êý¾Ý¿â³éÏó²ã”ÈÎÖØ¶øµÀÔ¶£¬Ê¹ÓÃPDOÕâÑùµÄ“Êý¾Ý¿â·ÃÎʳéÏó²ã”ÊÇÒ»¸ö²»´íµÄÑ¡Ôñ¡£
PDO->beginTransa ......
AddSlashes: ×Ö·û´®¼ÓÈëбÏß¡£
bin2hex: ¶þ½øÎ»×ª³ÉÊ®Áù½øÎ»¡£
Chop: È¥³ýÁ¬Ðø¿Õ°×¡£
Chr: ·µ»ØÐòÊýÖµµÄ×Ö·û¡£
chunk_split: ½«×Ö·û´®·Ö³ÉС¶Î¡£
convert_cyr_string: ת»»¹Å˹À·ò×Ö·û´®³ÉÆäËü×Ö·û´®¡£
crypt: ½«×Ö·û´®Óà DES ±àÂë¼ÓÃÜ¡£
echo: Êä³ö×Ö·û´®¡£
explode: Çпª×Ö·û´®¡£
flush: Çå³öÊä³ö»º ......
ǰһÕóÊÔÓà tokyo tyrant Åöµ½Ò»¸öÂé·³£¬
ÔÚphpÉÏÓÃmemcache½Ó¿Ú£¬È¡³öÊý¾ÝµÄʱºò£¬²»»á×Ô¶¯·´ÐòÁл¯¡£±ÈÈçÁËÒ»¸ö array(1,2,3,4,5)£¬³öÀ´¾ÍÊÇ 'a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;}' ÁË¡£
ÓÃ
Wireshark ¸ú×ÙÁËһϣ¬·¢Ïֺͱê×¼memcached·µ»ØµÄÊý¾ÝÀï²îÒ»¸ö×Ö½Ú¡£È¥¿´ÁËÏ memcached
ÐÒ飬·¢ÏÖÕâ¸ö×Ö½ÚÊǸ ......