Qaupot Blog
Software Engineering, Trip

PHP session garbage collecting

php.ini๋ฅผ ์—ด์–ด ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

PHP์—์„œ ์„ธ์…˜์€ ์ผ๋‹จ ์ƒ์„ฑ ๋œ ๋’ค์—, ๊ฐ€๋น„์ง€ ์ฝœ๋ ‰ํ„ฐ ๊ด€๋ฆฌ๋กœ์ง์— ์˜ํ•ด ์†Œ๋ฉธ๋ฉ๋‹ˆ๋‹ค. ๊ฐ€๋น„์ง€ ์ฝœ๋ ‰ํ„ฐ๋Š” ๋‹จ์ˆœํ•˜๊ฒŒ, ์š”์ฒญ์ด ๋“ค์–ด ์™”์„ ๋•Œ ํ™•๋ฅ ์ ์œผ๋กœ ์„ธ์…˜ ์ •๋ฆฌ ๋กœ์ง์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • session.gc_probability

    • ๊ธฐ๋ณธ๊ฐ’ : 1
  • session.gc_divisor

    • ๊ธฐ๋ณธ๊ฐ’ : 100ํ˜น์€ 1000
  • session.gc_maxlifetime

    • ๊ธฐ๋ณธ๊ฐ’ : 1440

gc_probability/gc_divisor์˜ ํ™•๋ฅ ๋กœ ๊ด€๋ฆฌ ๋กœ์ง์ด ํ˜ธ์ถœ๋˜๋ฉฐ, ๋‹ค์‹œ ๋งํ•ด 1 / 100์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋ฉด 1% ํ™•๋ฅ ๋กœ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ํ˜ธ์ถœ์ด ๋œ ํ›„, ์„ธ์…˜์ด ์ƒ์„ฑ๋œ ์‹œ๊ฐ„์œผ๋กœ๋ถ€ํ„ฐ session.gc_maxlifetime์ด ์ง€๋‚œ ์„ธ์…˜์„ ์ •๋ฆฌํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์š”์ฒญ ์ˆ˜๊ฐ€ ๋งŽ๋‹ค๋ฉด ๊ทธ๋งŒํผ ํ™•๋ฅ ์ด ๋‚ฎ๋”๋ผ๋„ ์„ธ์…˜ ๊ด€๋ฆฌ๋กœ์ง์ด ์ž์ฃผ ํ˜ธ์ถœ๋˜๊ฒ ์ง€๋งŒ, ์š”์ฒญ ์ˆ˜๊ฐ€ ์ ๋‹ค๋ฉด ์ƒ๊ฐ ์™ธ๋กœ ์„ธ์…˜์ด ์Œ“์ผ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๋„ˆ๋ฌด ๋งŽ์ด ์Œ“์ธ๋‹ค ์‹ถ๋‹ค๋ฉด session.gc_divisor์„ ์กฐ์ •ํ•ด ๋ณด์„ธ์š”.

์„ธ์…˜์„ ์ •๋ฆฌํ•˜๋Š”๋ฐ ์—ญ์‹œ ๋น„์šฉ์ด ์†Œ์š”๋˜๋ฏ€๋กœ, ๊ณผ๋„ํ•˜๊ฒŒ ํ˜ธ์ถœ๋˜๋Š”๊ฒƒ ์—ญ์‹œ ํ”ผํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ด ๋ธ”๋กœ๊ทธ๋Š” ๊ฐœ์ธ ๋ธ”๋กœ๊ทธ์ž…๋‹ˆ๋‹ค. ๊ฒŒ์‹œ๊ธ€์€ ์˜ค๋ฅ˜๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์„ ์ˆ˜ ์žˆ์ง€๋งŒ, ์ €์ž๋Š” ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฒŒ์‹œ๊ธ€์— ๋ณ„๋„์˜ ๊ณ ์ง€๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, ํฌ๋ฆฌ์—์ดํ‹ฐ๋ธŒ ์ปค๋จผ์ฆˆ ์ €์ž‘์žํ‘œ์‹œ-๋น„์˜๋ฆฌ-๋ณ€๊ฒฝ๊ธˆ์ง€ 4.0 ๋ผ์ด์„ ์Šค๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

This blog is personal blog. published posts may contain some errors, but author doing efforts to clear errors.
If post have not notice of license, it under creative commons Attribution-NonCommercial-NoDerivatives 4.0.