본문 바로가기
linux

php session 자동 삭제 설정

by 하이바네 2021. 9. 3.
반응형

apache2과 php 7.3버전을 우분투에 설치하여 사용 하던 중 세션 파일들이 계속 쌓이는 것을 확인했다.(뭔가 잘못된거 같은 불길한 예감)

 

일부 업로드 제한이나 post크기 같은것만 수정을 하고 사용하고 있었는데, 찾아보니 garbage collector에 대한 설정을 해줘야 한다고 한다. 

 

해당 설정은 php.ini내에 존재하며

 

session.gc_probability = 1
session.gc_divisor = 100

session.gc_maxlifetime = 1440

 

위의 3개에 대한 값을 넣어야 한다. maxlifetime은 저 시간 이후로는 garbage로 취급을 한다는 것이다.

 

그리고 나머지는 gc_probability / gc_divisor   해당 식의 확률로 요청이 있을때마다 동작을 한다는 것이다.

 

정확하게는 php.ini에 적혀 있다.

 

 

; Defines the probability that the 'garbage collection' process is started on every
; session initialization. The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts on each request.
; For high volume production servers, using a value of 1000 is a more efficient approach.

 

 

아니 근데 기본값으로 probability가 0으로 들어있는건 좀...너무하지 않니?

728x90

댓글