티스토리 뷰
php 세션 공유 방법
NFS, SAMBA
세션 특성상 read, write 가 빈번하게 일어남 적합하지 않음
|
DBMS
세션데이터를 DB에 저장 (보편적으로 사용되는 방법) 접속자가 많으면 DB 부하 발생 |
Daemon
데몬을 이용하여 세션 공유 세션 서버를 따로 구축하기에 적합한 방법 |
sharedance (데몬 형식)
환경 : centos7 64bit
사전패키지 설치
yum install gcc libevent-devel wget make
|
sharedance 설치
wget https://download.pureftpd.org/pub/sharedance/sharedance-0.6.tar.gz tar xvfz sharedance-0.6.tar.gz ./configure && make && make install
|
PHP (웹) 서버 설정시 필요한 디폴트 파일
[root@localhost php]# ll /usr/local/src/sharedance-0.6/php 합계 36 -rw-r--r-- 1 root root 7836 8월 29 14:58 Makefile -rw-r--r-- 1 1000 wheel 105 8월 31 2004 Makefile.am -rw-r--r-- 1 1000 wheel 7690 2월 19 2006 Makefile.in -rw-r--r-- 1 1000 wheel 965 11월 7 2004 session_handler.php -rw-r--r-- 1 1000 wheel 3593 2월 19 2006 sharedance.php -rw-r--r-- 1 1000 wheel 347 11월 7 2004 test_session.php -rw-r--r-- 1 1000 wheel 270 8월 31 2004 test_sharedance.php
|
WEB 서버 전송할 파일
session_handler.php sharedance.php
|
세션 저장 경로 디렉토리 생성 (선택)
mkdir /var/tmp/sharedance
|
별 다른 경우가 아니면 /dev/shm 디렉토리 이용 (메모리)
tmpfs tmpfs 496M 0 496M 0% /dev/shm
|
sharedance 데몬 실행
sharedanced --directory=/dev/shm&
|
ps -ef
root 23221 984 0 15:01 pts/0 00:00:00 sharedanced [SERVER] root 23222 23221 0 15:01 pts/0 00:00:00 sharedanced [CLEANUP]
|
tcp 0 0 0.0.0.0:1042 0.0.0.0:* LISTEN 23221/sharedanced
|
PHP (웹) 서버
sharedance 디렉토리로 부터 적절한 위치에 복사
vim session_handler.php
define('SESSION_HANDLER_HOST', '192.168.0.100');
|
: 세션서버 지정 (localhost, 혹은 아이피, 도메인)
vim session_sharedance.php
define('SHAREDANCE_DEFAULT_PORT', 1042); define('SHAREDANCE_DEFAULT_TIMEOUT', 10); |
: 포트와 timeout 시간 지정
웹서버 php.ini
[Session] auto_prepend_file = /디렉토리경로/session_handler.php session.save_handler = user |
웹서버 재시작
: 웹사이트 로그인시 세션서버 디렉토리 /tmp/shm 에 파일 생성 확인
세션 공유 테스트 위한 PHP 소스 링크
https://zetawiki.com/wiki/PHP_%EC%84%B8%EC%85%98_%EB%A1%9C%EA%B7%B8%EC%9D%B8_%EA%B5%AC%ED%98%84
|
'WEB' 카테고리의 다른 글
session 세션 공유 (sharedance) (0) | 2018.08.29 |
---|---|
mod_rewrite (파일이 없을때 대체 파일 제공하기) (0) | 2018.07.30 |
[mpm_prefork:error] [pid 10161] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting (0) | 2017.10.12 |
워드프레스 구버젼 (옜날 버전) 설치하기 (0) | 2017.09.29 |
mod_rewrite 예제) (0) | 2017.09.13 |
Let'sEncrypt 명령어 하나로 셋팅하기 (1) | 2017.09.07 |