ÔõôʹÓÃThinkPHP¾ÙÐÐÂþÑÜʽ°²ÅÅ
Ò»¡¢¸ºÔØƽºâ
ÔÚ¾ÙÐÐÂþÑÜʽ°²ÅŵÄʱ¼ä£¬¸ºÔØƽºâÊDZز»¿ÉÉÙµÄÒ»²¿·Ö£¬Ëü¿ÉÒÔͨ¹ý½«ÇëÇó·ÖÅɵ½¶à¸öЧÀÍÆ÷ÉÏÀ´Æ½ºâЧÀÍÆ÷µÄ¸ºÔØ¡£Õë¶ÔÕâÒ»ÎÊÌ⣬ÎÒÃÇ¿ÉÒÔʹÓà Nginx À´¾ÙÐÐʵÏÖ¡£
NginxÊÇÒ»¿î¸ßЧµÄWebЧÀÍÆ÷£¬²»µ«¿É×÷Ϊ¸ºÔØƽºâÆ÷£¬»¹¿É³äµ±¾²Ì¬×ÊԴЧÀÍÆ÷¡£½öÐèÔÚ Nginx ÉϾÙÐÐÉèÖ㬱ã¿ÉʵÏÖʹÓà Nginx ¾ÙÐиºÔØƽºâ¡£
ÒÔÏÂÊÇÒ»¸ö½ÏΪ¼òÆ Nginx ÉèÖÃʾÀý£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
upstream backend { server backend1; server backend2; server backend3; } server { listen 80; location / { proxy_pass http://backend; } }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃÖУ¬ÎÒÃÇʹÓà upstream Ö¸Áî½ç˵ÁËÒ»¸öºó¶ËЧÀÍÆ÷µÄÁÐ±í£¬È»ºó½«Õâ¸öÁбíת´ï¸ø proxy_pass Ö¸Áî¡£ÕâÑù£¬µ±ÎÒÃǵÄÇëÇóµÖ´ï Nginx ºó£¬Nginx »á×Ô¶¯½«ÇëÇóת·¢µ½ºó¶ËЧÀÍÆ÷ÉÏ¡£
¶þ¡¢Session ¹²Ïí
ÔÚÂþÑÜʽ°²ÅÅÖУ¬ÎÒÃǾ³£ÐèÒªÔÚ¶à¸öЧÀÍÆ÷Ö®¼ä¹²ÏíÊý¾Ý£¬ÀýÈç Session Êý¾Ý¡£ÈôÊÇÎÒÃÇ´¿´âµØ½« Session Êý¾Ý´æ·ÅÔÚij¸öЧÀÍÆ÷µÄÄÚ´æÖУ¬ÄÇôÆäËûЧÀÍÆ÷½«ÎÞ·¨»á¼ûÕâ¸ö Session Êý¾Ý¡£
Òª½â¾öÕâ¸öÎÊÌ⣬ÎÒÃÇ¿ÉÒÔ½ÓÄÉÄڴ滺´æЧÀÍ£¬ÀýÈç Redis »ò Memcached À´ÊµÏÖ¡£Í¨¹ýÕâЩЧÀÍ£¬¿ÉÒÔʵÏÖÊý¾ÝÔÚ¶ą̀ЧÀÍÆ÷Ö®¼äµÄ¹²Ïí£¬½«Æä´æ·ÅÔÚÂþÑÜʽÄڴ滺´æÖС£
ÔÚ ThinkPHP ÖУ¬ÎÒÃÇ¿ÉÒÔ½èÖú think\cache\driver\Redis »ò think\cache\driver\Memcached Àà¾ÙÐлº´æ²Ù×÷¡£ÒÔÏÂÊÇÒ»¸öʹÓà Redis ¾ÙÐлº´æµÄÀý×Ó£º
$redis = new \think\cache\driver\Redis(); $redis->set('key', 'value'); $value = $redis->get('key');
µÇ¼ºó¸´ÖÆ
Èý¡¢Îļþ¹²Ïí
ÓÐЩӦÓÃÐèÒª¹²Ïí¶àÖÖÎļþ£¬ÀýÈç´úÂ롢ͼƬ¡¢Îı¾µÈµÈ£¬³ýÁË Session Êý¾Ý¡£ÎªÁËʵÏÖÎļþ¹²Ïí£¬ÎÒÃÇ¿ÉÒÔʹÓÃÂþÑÜʽÎļþϵͳÀ´¾ÙÐд洢¡£
ÂþÑÜʽÎļþϵͳ¿ÉÒÔ½«ÎļþÊèÉ¢ÔÚ¶ą̀ЧÀÍÆ÷ÉϾÙÐд洢£¬ÕâÑùÏà±È¹Å°åµÄµ¥»ú´æ´¢£¬ÂþÑÜʽ´æ´¢Ô½·¢Çå¾²¿É¿¿¡£ÔÚ ThinkPHP ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓà think\filesystem\driver\Qiniu À´²Ù×÷ÆßÅ£Ôƹ¤¾ß´æ´¢£¬ÊµÏÖÎļþµÄÂþÑÜʽ´æ´¢¡£
ÒÔÏÂÊÇÒ»¸öʹÓÃÆßÅ£Ôƹ¤¾ß´æ´¢¾ÙÐÐÎļþ´æ´¢µÄÀý×Ó£º
$config = [ 'accessKey' => 'your access key', 'secretKey' => 'your secret key', 'bucket' => 'your bucket name', ]; $filesystem = \think\filesystem\Driver::Qiniu($config); // ÉÏ´«Îļþ $filesystem->write('test.txt', 'hello, world!'); // ÏÂÔØÎļþ $content = $filesystem->read('test.txt');
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇÔõôʹÓÃThinkPHP¾ÙÐÐÂþÑÜʽ°²ÅŵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡