laravel session ´æ´¢Ê§°Ü
½üÄêÀ´£¬laravel ¿ò¼ÜÔÚ web ¿ª·¢ÁìÓò»ñµÃÔ½À´Ô½ÆÕ±éµÄÓ¦Óã¬ÆäÖÐ session »úÖÆÊÇ laravel ¿ò¼ÜµÄÒ»¸öÖ÷Òª×é³É²¿·Ö¡£session ¿ÉÒÔÓÃÀ´ÔÚÇëÇóÖ®¼ä¹²ÏíÊý¾Ý£¬Àû±ã¿ª·¢Õß¿ª·¢»ùÓÚÓû§µÇ¼״̬µÈ¹¦Ð§¡£¿ÉÊÇÔÚʹÓà session µÄÀú³ÌÖУ¬ÎÒÃÇÒ²¿ÉÄÜ»áÓöµ½Ò»Ð©ÎÊÌ⣬ºÃ±È session ´æ´¢Ê§°ÜµÄÇéÐΡ£
ÈôÊÇÎÒÃÇÔÚ¿ª·¢Öз¢Ã÷ Session ´æ´¢Ê§°Ü£¬Ò»Ñùƽ³£ÓÐÒÔϼ¸¸ö¿ÉÄܵÄÔµ¹ÊÔÓÉ£º
´ÅÅÌ¿Õ¼äȱ·¦
Laravel ĬÈÏÇéÐÎÏÂʹÓÃÎļþ´æ´¢ Session£¬ÈôÊÇ´ÅÅÌ¿Õ¼äȱ·¦£¬ÄÇô Session Îļþ½«ÎÞ·¨Õý³£Ð´È룬´Ó¶øµ¼Ö Session ´æ´¢Ê§°Ü¡£´Ëʱ£¬ÎÒÃÇÐèÒª¼ì²é´ÅÅÌ¿Õ¼äÊÇ·ñ¸»×㣬¿ÉÒÔʹÓÃÏÂÁî df -h ¼ì²éÎļþϵͳ´ÅÅÌ¿Õ¼äʹÓÃÇéÐΡ£
ÈôÊÇÊÇÓÉÓÚ´ÅÅÌ¿Õ¼äȱ·¦µ¼Ö嵀 Session ´æ´¢Ê§°Ü£¬½â¾öÒªÁì½ÏÁ¿¼òÆÓ£¬Ö»ÐèÒªÊÍ·ÅһЩ´ÅÅÌ¿Õ¼ä»òÕß½« Session ´æ´¢µ½ÆäËûλÖü´¿É¡£
PHP »á»°Îļþ´æ´¢Â·¾¶ÉèÖùýʧ
³ýÁËÉÏÃæµÄÇéÐΣ¬ÈôÊÇ Laravel ËùÔڵĻúеÉÏÓжà¸ö PHP °æ±¾£¬²¢ÇÒ PHP.ini ÖÐ session.save_path ÉèÖùýʧ£¬Ò²»áµ¼Ö Session ´æ´¢Ê§°Ü¡£Session ĬÈÏ´æ´¢ÔÚ PHP »á»°ÎļþÖУ¬Òò´ËÎÒÃÇÐèҪȷ±£ PHP µÄ»á»°Îļþ´æ´¢Â·¾¶ÉèÖÃ׼ȷ¡£
¿ÉÒÔÔÚÏÂÁîÐÐÖÐʹÓà php -i | grep session.save_path Éó²é PHP »á»°Îļþ´æ´¢Â·¾¶ÊÇ·ñÉèÖÃ׼ȷ£¬ÈôÊDz»×¼È·¾ÍÐèҪͨ¹ýÐÞ¸Ä php.ini Îļþ»òÕßÔÚ´úÂëÖÐÉèÖà session.save_handler ÒÔ¼° session.save_path À´Ö¸¶¨×¼È·µÄλÖá£
»á»°ÎļþȨÏÞÎÊÌâ
Laravel ʹÓÃÎļþ´æ´¢ Session£¬Ä¬ÈÏÇéÐÎÏ»Ὣ Session Îļþ´æ´¢ÔÚ storage/framework/sessions Ŀ¼ÏÂÃæ¡£ÈôÊÇÕâ¸öĿ¼µÄȨÏÞÉèÖò»×¼È·£¬½«»áµ¼ÖÂдÈë Session Îļþʧ°Ü£¬´Ó¶øµ¼Ö Session ´æ´¢Ê§°Ü¡£
ÔÚ Linux ϵͳÖУ¬session Îļþ¼ÐȨÏÞͨ³£ÊÇ 755 »òÕß 777£¬¿ÉÒÔÔÚÏÂÁîÐÐÖÐʹÓà ls -l Éó²éÄ¿½ñÎļþ¼ÐµÄȨÏÞÉèÖ㬲¢¶ÔÆä¾ÙÐÐÐ޸ġ£
ÖÐÑë¼þÎÊÌâ
ÔÚʹÓà Laravel µÄ¿ª·¢ÖУ¬ÖÐÑë¼þ£¨Middleware£©Ò²¿ÉÄÜ»áÓ°Ïì Session µÄ´æ´¢¡£ÖÐÑë¼þÊÇÒ»ÖÖ¹ýÂËÆ÷£¬¿ÉÒÔÔÚ HTTP ÇëÇó½øÈëÓ¦ÓóÌÐò֮ǰ»òÕßÍÑÀëÓ¦ÓóÌÐòÖ®ºó¶ÔÇëÇóºÍÏìÓ¦¾ÙÐйýÂË¡£Session ÖÐÑë¼þÔòÓÃÓÚÑéÖ¤Óû§ÊÇ·ñµÇ¼µÈ¹¦Ð§£¬ÈôÊÇÖÐÑë¼þµÄÓªÒµÂß¼²»×¼È·£¬Ò²»áµ¼Ö Session ´æ´¢Ê§°Ü¡£
Òò´ËÔÚʹÓà Session ÖÐÑë¼þʱ£¬ÐèÒªÌØÊâ×¢ÖØÖÐÑë¼þµÄ˳Ðò£¬È·±£ÓªÒµÂ߼׼ȷ¡£
Session Çý¶¯ÉèÖÃÎÊÌâ
Laravel ¿ò¼ÜÖ§³Ö¶àÖÖ Session ´æ´¢Çý¶¯£¬ºÃ±È redis¡¢memcached¡¢cookie µÈ¡£ÔÚʹÓòî±ðµÄ´æ´¢Çý¶¯Ê±£¬ÎÒÃÇÐèҪȷ±£ÉèÖÃÎļþ config/session.php ÖÐµÄ driver ÉèÖÃ׼ȷ¡£
ÈôÊÇ Session ÓÉÓÚÇý¶¯ÉèÖùýʧ¶øÎÞ·¨´æ´¢£¬ÐèÒªÔÚÉèÖÃÎļþÖÐÉèÖÃ׼ȷµÄ driver¡£
HttpSession ÎļþÒÑÂú
HttpSession Ò²¾ÍÊÇ tomcat µÄ session »úÖÆ£¬ÈôÊÇÔÚ¿ª·¢ÖÐÐèҪʹÓà HttpSession£¬ÄÇô Session Ò²¿ÉÄÜ»áÓÉÓÚ HttpSession ÎļþÒÑÂúµ¼Ö´洢ʧ°Ü¡£´ËʱÐèÒªÕûÀí HttpSession Îļþ¡£
ÈôÊÇ·ºÆðÒÔÉÏÌáµ½µÄÎÊÌ⣬ÐèҪƾ֤ÏêϸÇéÐΣ¬¼ì²éÏìÓ¦µÄÉèÖá¢ÉèÖõȣ¬ÒÔÈ·±£ Session ´æ´¢Õý³£¡£Í¬Ê±£¬ÔÚʹÓà Laravel Session »úÖÆʱ£¬»¹ÐèҪעÖØÒÔϼ¸µã£º
ÐèҪƾ֤×Ô¼ºµÄÐèÇóÉèÖà Session ÓâÆÚʱ¼ä¡£
ÈôÊÇÐèҪʹÓà redis µÈ·ÇÎļþ´æ´¢Çý¶¯Ê±£¬ÐèÒªÏÈ×°ÖöÔÓ¦µÄ PHP À©Õ¹¡£
ÐèÒª¶Ô Session Êý¾Ý¾ÙÐмÓÃÜ£¬²»Òª´æ´¢Ãô¸ÐÐÅÏ¢¡£
×ܽá
Laravel Session µÄ´æ´¢Ê§°Ü¿ÉÄÜÓɶàÖÖÔµ¹ÊÔÓɵ¼Ö£¬ÐèÒªÎÒÃÇƾ֤ÏêϸÇéÐξÙÐÐÅŲ顣ÎÒÃÇÐèҪȷ±£´ÅÅ̿ռ主×㣬PHP »á»°Îļþ´æ´¢Â·¾¶ÉèÖÃ׼ȷ£¬ÎļþȨÏÞ׼ȷ£¬»º´æÇý¶¯ÉèÖÃ׼ȷ£¬ÓªÒµÂ߼׼ȷ£¬Session Êý¾Ý¼ÓÃܵȡ£Ö»ÒªÎÒÃÇÔÚʹÓà Session »úÖÆʱעÖØÒÔÉÏϸ½Ú£¬¾Í¿ÉÒÔ°ü¹ÜÓ¦ÓóÌÐòµÄÕý³£ÔËÐС£
ÒÔÉϾÍÊÇlaravel session ´æ´¢Ê§°ÜµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡