Menu

PHP Doesn't Really Die After Every Request: OPcache, PHP-FPM and Worker Mode in Production
📰

PHP Doesn't Really Die After Every Request: OPcache, PHP-FPM and Worker Mode in Production

DEV Community: php·EME GUG·6 days ago
#LYOtI9Gp
#devto#dev#request#opcache#worker
Reading 0:00
15s threshold

Câu "PHP chết sau mỗi request" được lặp lại nhiều đến mức nhiều dev tin rằng mỗi request đều khởi động lại toàn bộ PHP. Thực tế không phải vậy. Thứ bị dọn sau mỗi request là request state : biến, object, static property. Process PHP-FPM vẫn sống, và OPcache vẫn giữ bytecode trong shared memory. Hiểu đúng ranh giới này giúp bạn tune server có cơ sở, đọc đúng số liệu, và tránh một loại bug rất nguy hiểm khi chuyển sang worker mode. Bài này đi qua những gì thực sự xảy ra bên trong Zend Engine, kèm các lệnh và config dùng được ngay với PHP 8.4 trở lên.

Điều gì sống, điều gì chết sau một request?

PHP có hai vòng đời lồng nhau. Vòng ngoài là của process: module startup (MINIT) chạy khi process khởi động, module shutdown (MSHUTDOWN) chạy khi process tắt. Vòng trong là của request: RINIT ở đầu request, RSHUTDOWN ở cuối request.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.