PHP ÐòÁл¯£¨serialize£©¸ñʽÏê½â(4)
6£®×Ô¶¨Òå¶ÔÏóÐòÁл¯
6.1£®PHP 4 ÖÐ×Ô¶¨Òå¶ÔÏóÐòÁл¯
PHP 4 ÖÐÌṩÁË __sleep ºÍ __wakeup ÕâÁ½¸ö·½·¨À´×Ô¶¨Òå¶ÔÏóµÄÐòÁл¯¡£²»¹ýÕâÁ½¸öº¯Êý²¢²»¸Ä±ä¶ÔÏóÐòÁл¯µÄ¸ñʽ£¬Ó°ÏìµÄ½ö½öÊDZ»ÐòÁл¯×ֶεĸöÊý¡£¹ØÓÚËüÃǵĽéÉÜ£¬ÔÚ PHP ÊÖ²áÖÐдµÄ»¹Ëã±È½ÏÏêϸ¡£ÕâÀï¾Í²»ÔÙ¶à×ö½éÉÜÁË¡£
6.2£®PHP 5 ÖÐ×Ô¶¨Òå¶ÔÏóÐòÁл¯
PHP 5 ÖÐÔö¼ÓÁ˽ӿڣ¨interface£©¹¦ÄÜ¡£PHP 5 ±¾ÉíÌṩÁËÒ»¸ö Serializable ½Ó¿Ú£¬Èç¹ûÓû§ÔÚ×Ô¼º¶¨ÒåµÄÀàÖÐʵÏÖÁËÕâ¸ö½Ó¿Ú£¬ÄÇôÔÚ¸ÃÀàµÄ¶ÔÏóÐòÁл¯Ê±£¬¾Í»á±»°´ÕÕÓû§ÊµÏֵķ½Ê½È¥½øÐÐÐòÁл¯£¬²¢ÇÒÐòÁл¯ºóµÄ±êʾ²»ÔÙÊÇ O£¬¶ø¸ÄΪ C¡£C ±êʾµÄ¸ñʽÈçÏ£º
C:<name length>:"<class name>":<data length>:{<data>}
ÆäÖÐ <name length> ±íʾÀàÃû <class name> µÄ³¤¶È£¬<data length> ±íʾ×Ô¶¨ÒåÐòÁл¯Êý¾Ý <data> µÄ³¤¶È£¬¶ø×Ô¶¨ÒåµÄÐòÁл¯Êý¾Ý <data> ÊÇÍêÈ«µÄÓû§×Ô¼º¶¨ÒåµÄ¸ñʽ£¬Óë PHP ÐòÁл¯¸ñʽ¿ÉÒÔÍêÈ«Î޹أ¬Õⲿ·ÖÊý¾ÝÓÉÓû§×Ô¼ºÊµÏÖµÄÐòÁл¯ºÍ·´ÐòÁл¯½Ó¿Ú·½·¨À´¹ÜÀí¡£
Serializable ½Ó¿ÚÖж¨ÒåÁË 2 ¸ö·½·¨£¬serialize() ºÍ unserialize($data)£¬ÕâÁ½¸ö·½·¨²»»á±»Ö±½Óµ÷Ó㬶øÊÇÔÚµ÷Óà PHP ÐòÁл¯º¯Êýʱ£¬±»×Ô¶¯µ÷Óá£ÆäÖÐ serialize º¯ÊýûÓвÎÊý£¬ËüµÄ·µ»ØÖµ¾ÍÊÇ <data> µÄÄÚÈÝ¡£¶ø unserialize($data) ÓÐÒ»¸ö²ÎÊý $data£¬Õâ¸ö²ÎÊýµÄÖµ¾ÍÊÇ <data> µÄÄÚÈÝ¡£ÕâÑù´ó¼ÒÓ¦¸Ã¾ÍÃ÷°×ÁË£¬Êµ¼ÊÉϽӿÚÖÐ serialize ·½·¨¾ÍÊÇÈÃÓû§À´×Ô¼ºÐòÁл¯¶ÔÏóÖеÄÄÚÈÝ£¬ÐòÁл¯ºóµÄÄÚÈݸñʽ£¬PHP ²¢²»¹ØÐÄ£¬PHP Ö»¸ºÔð°ÑËü³äÌîµ½ <data> ÖУ¬µÈµ½·´ÐòÁл¯Ê±£¬PHP Ö»¸ºÔðÈ¡³öÕⲿ·ÖÄÚÈÝ£¬È»ºó´«¸øÓû§ÊµÏÖµÄ unserialize($data) ½Ó¿Ú·½·¨£¬ÈÃÓû§×Ô¼ºÈ¥·´ÐòÁл¯Õⲿ·ÖÄÚÈÝ¡£
ÏÂÃæ¾Ù¸ö¼òµ¥µÄÀý×Ó£¬À´ËµÃ÷ Serializable ½Ó¿ÚµÄʹÓãº
class MyClass implements Serializable { public $member; function MyClass() { $this->member = 'member value'; } public function serialize() { return wddx_serialize_value($this->member); } public function unserialize($data) { $this->member = wddx_deserialize($data); } } $a = new MyClass(); echo serialize($a); echo "\n"; print_r(unserialize(serialize($a)));Êä³ö½á¹ûΪ£¨ä¯ÀÀÆ÷ÖеÄÔ´´úÂ룩£º
C:7:"MyClass":90:{<wddxPacket version='1.0'><header/><data><string>member value</string></data></wddxPacket>} MyClass Object ( [member] => member value )
Òò´ËÈç¹ûÏëÓÃÆäËüÓïÑÔÀ´ÊµÏÖ PHP ÐòÁл¯ÖÐµÄ C ±êʾµÄ»°£¬Ò²ÐèÒªÌṩһÖÖÕâÑùµÄ»úÖÆ£¬ÈÃÓû§×Ô¶¨ÒåÀàʱ,Äܹ»×Ô¼ºÔÚ·´ÐòÁл¯Ê±´¦Àí <data> ÄÚÈÝ£¬·ñÔò£¬ÕâЩÄÚÈݾÍÎÞ·¨±»·´ÐòÁл¯ÁË¡£
7£®Unicode ×Ö·û´®µÄÐòÁл¯
ºÃÁË£¬×îºóÔÙ̸̸ PHP 6 ÖйØÓÚ Unicode ×Ö·û´®ÐòÁл¯µÄÎÊÌâ°É¡£
˵ʵ»°£¬ÎÒ²»Ôõôϲ»¶°Ñ×Ö·û´®¸ã³ÉË«×Ö½Ú Unicode ÕâÖÖ±àÂëµÄ¶«Î÷¡£JavaScript ÖÐÒ²ÊÇÓÃÕâÑùµÄ×Ö·û´®£¬Òò´ËÔÚ´¦Àí×Ö½ÚÁ÷µÄ¶«Î÷ʱ£¬·´¶ø·Ç³£µÄ²»·½±ã¡£C# ËäȻҲÊÇÓÃÕâÖÖ·½Ê½À´±àÂë×Ö·û´®£¬²»¹ý»¹ºÃµÄÊÇ£¬ËüÌṩÁËÈ«ÃæµÄ±àÂëת»»»úÖÆ£¬¶øÇÒÌṩÕâÖÖ×Ö·û´®µ½×Ö½ÚÁ÷£¨Êµ¼ÊÉÏÊǵ½×Ö½ÚÊý×飩µÄת»»£¬ËùÒÔ´¦ÀíÆðÀ´»¹ ËãÊÇ¿ÉÒÔ¡£µ«ÊǶÔÓÚ²»ÊìϤÕâ¸öµÄÈËÀ´Ëµ£¬×ªÀ´×ªÈ¥¾ÍÊǸöÂé·³¡£
PHP 6 ֮ǰһֱÊÇ°´×Ö½ÚÀ´±àÂë×Ö·û´®µÄ£¬µ½ÁË PHP 6 ͻȻð³ö¸ö Unicode ±àÂëµÄ×Ö·û´®À´£¬ËäÈ»ÊÇ¿ÉÑ¡µÄ£¬µ«ÈÔÈ»ÈÃÈ˾õµÃ·Ç³£²»Êæ·þ£¬Èç¹ûÅäÖò»µ±£¬ÀϵijÌÐò¼æÈÝÐÔ¶¼³ÉÎÊÌâ¡£
µ±È»¼ÓÁËÕâ¸ö¶«Î÷ÒÔºó£¬Ðí¶àÀϵÄÓë×Ö·û´®Óйصĺ¯Êý¶¼½øÐÐÁËÐ޸ġ£ÐòÁл¯º¯ÊýÒ²²»ÀýÍâ¡£Òò´Ë£¬PHP 6 ÖÐÔö¼ÓÁËרÃÅµÄ Unicode ×Ö·û´®ÐòÁл¯±êʾ U¡£PHP 6 ÖÐ¶Ô Unicode ×Ö·û´®µÄÐòÁл¯¸ñʽÈçÏ£º
U:<length>:"<unicode string>";
ÕâÀï <length> ÊÇÖ¸Ô Unicode String µÄ³¤¶È£¬¶ø²»ÊÇ <unicode string> µÄ³¤¶È£¬ÒòΪ <unicode string> ÊǾ¹ý±àÂëÒÔºóµÄ×Ö½ÚÁ÷ÁË¡£
µ«ÊÇ»¹ÓÐÒ»µãҪעÒ⣬<length> ¾¡¹ÜÊÇÔ Unicode String µÄ³¤¶È£¬µ«ÊÇÒ²²»ÊÇÖ»ËüµÄ×Ö½ÚÊý£¬µ±È»Ò²²»ÍêÈ«ÊÇÖ¸ËüµÄ×Ö·ûÊý£¬È·ÇеÄ˵ÊÇÖ®ËüµÄ×Ö·ûµ¥Î»Êý¡£ÒòΪ Unicode String ÖвÉÓõÄÊÇ UTF16 ±àÂ룬ÕâÖÖ±àÂ뷽ʽʹÓà 16 λÀ´±íʾһ¸ö×Ö·ûµÄ£¬µ«ÊDz¢²»ÊÇËùÓеĶ¼ÊÇ¿ÉÒÔÓà 16 λ±íʾµÄ£¬Òò´ËÓÐЩ×Ö·ûÐèÒªÁ½¸ö 16 λÀ´±íʾһ¸ö×Ö·û¡£Òò´Ë£¬ÔÚ UTF16 ±àÂëÖУ¬16 λ×Ö·ûËã×÷Ò»¸ö×Ö·ûµ¥Î»£¬Ò»¸öʵ¼ÊµÄ×Ö·û¿ÉÄܾÍÊÇÒ»¸ö×Ö·ûµ¥Î»£¬Ò²ÓпÉÄÜÓÉÁ½¸ö×Ö·ûµ¥Î»×é³É¡£Òò´Ë£¬ Unicode String ÖÐ×Ö·ûÊý²¢²»×ÜÊǵÈÓÚ×Ö·ûµ¥Î»Êý£¬¶øÕâÀïµÄ <length> Ö¸µÄ¾ÍÊÇ×Ö·ûµ¥Î»Êý£¬¶ø²»ÊÇ×Ö·ûÊý¡£
ÄÇ <unicode string> ÓÖÊÇÔõÑù±»±àÂëµÄÄØ£¿Êµ¼ÊÉÏ£¬ËüµÄ±àÂëÒ²ºÜ¼òµ¥£¬¶ÔÓÚ±àÂëСÓÚ 128 µÄ×Ö·û£¨µ«²»°üÀ¨ \£©£¬°´ÕÕµ¥¸ö×Ö½ÚдÈ룬¶ÔÓÚ´óÓÚ 128 µÄ×Ö·ûºÍ \ ×Ö·û£¬Ôòת»¯Îª 16 ½øÖƱàÂëµÄ×Ö·û´®£¬ÒÔ \ ×÷Ϊ¿ªÍ·£¬ºóÃæËĸö×Ö½Ú·Ö±ðÊÇÕâ¸ö×Ö·ûµ¥Î»µÄ 16 ½øÖƱàÂ룬˳Ðò°´ÕÕÓɸßλµ½µÍλÅÅÁУ¬Ò²¾ÍÊÇµÚ 16-13 λËù¶ÔÓ¦µÄ16½øÖÆÊý×Ö×Ö·û£¨abcdef Õ⼸¸ö×ÖĸÊÇСд£©×÷ΪµÚÒ»¸ö×Ö½Ú£¬µÚ 12-9 λ×÷ΪµÚ¶þ¸ö×Ö½Ú£¬µÚ 8-5 λ×÷ΪµÚÈý¸ö×Ö½Ú£¬×îºóµÄµÚ 4-1 λ×÷ΪµÚËĸö×Ö½Ú¡£ÒÀ´Î±àÂëÏÂÀ´£¬µÃµ½µÄ¾ÍÊÇ <uncode string> µÄÄÚÈÝÁË¡£
ÎÒÈÏΪ¶ÔÓÚÆäËûÓïÑÔÀ´Ëµ£¬Ã»ÓбØҪʵÏÖÕâÖÖÐòÁл¯·½Ê½£¬ÒòΪÓÃÕâÖÖ·½Ê½ÐòÁл¯µÄÄÚÈÝ£¬¶ÔÓÚÄ¿Ç°µÄÖ÷Á÷ PHP ·þÎñÆ÷À´Ëµ¶¼ÊDz»Ö§³ÖµÄ£¬²»¹ýµ¹ÊÇ¿ÉÒÔʵÏÖËüµÄ·´ÐòÁл¯£¬ÕâÑù½«À´¼´Ê¹¸ú PHP 6 ½øÐÐÊý¾Ý½»»»£¬Ò²¿ÉÒÔ»¥Ïà¶Á¶®ÁË¡£
8£®²Î¿¼ÎÄÏ×
PHP 3 ÖйØÓÚÐòÁл¯ºÍ·´ÐòÁл¯µÄÔ´´úÂë
PHP ÊÖ²áÖйØÓÚÐòÁл¯ºÍ·´ÐòÁл¯µÄ½éÉÜ
Using Serialized PHP with Yahoo! Web Services
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ