- Platform: YouTube
- Channel/Creator: Chris Fidao
- Duration: 00:05:00
- Release Date: Aug 31, 2023
- Video Link: https://www.youtube.com/watch?v=vohsuhwWvpw
Disclaimer: This is a personal summary and interpretation based on a YouTube video. It is not official material and not endorsed by the original creator. All rights remain with the respective creators.
This document summarizes the key takeaways from the video. I highly recommend watching the full video for visual context and coding demonstrations.
- I summarize key points to help you learn and review quickly.
- Simply click on
Ask AIlinks to dive into any topic you want.
Teach Me: 5 Years Old | Beginner | Intermediate | Advanced | (reset auto redirect)
Learn Differently: Analogy | Storytelling | Cheatsheet | Mindmap | Flashcards | Practical Projects | Code Examples | Common Mistakes
Check Understanding: Generate Quiz | Interview Me | Refactor Challenge | Assessment Rubric | Next Steps
- Summary: PHP-FPM acts as an intermediary between Nginx and your PHP application, using the FastCGI protocol to spawn a separate PHP process for each incoming web request. Each child process can only handle one request at a time, so to manage concurrency, multiple processes are needed.
- Key Takeaway: The max_children setting caps the total number of processes, directly limiting how many concurrent requests your app can process before hitting resource issues or errors.
- Ask AI: PHP-FPM Basics
- Summary: If max_children is too low, even if your server has available resources, incoming requests pile up once the process limit is reached, leading to 502 Gateway errors in Nginx as PHP-FPM can't spawn more processes.
- Key Example: Sending a flood of requests to a server with max_children set to 20 results in errors visible in the PHP-FPM log, showing the process limit being hit and requests being rejected.
- Ask AI: PHP-FPM Concurrent Requests
- Summary: Base max_children on your server's available RAM, divided by the average memory used per request (e.g., monitor with tools like Sentry or PHP's memory_get_peak_usage()). Apply a buffer to avoid exhausting all RAM.
- Key Example: For a 4GB server, use 3000MB as a buffer and divide by 50MB per request to get 60 processes. This allows handling around 60 concurrent requests, though staggering can support slightly more.
- Ask AI: Setting PHP-FPM Max Children
- Summary: Beyond max_children, configure start_servers for initial idle processes, min_spare_servers and max_spare_servers for dynamic scaling, and max_requests to restart processes after a set number of requests to prevent memory leaks.
- Key Example: Set start_servers to 5, min_spare_servers to 5, max_spare_servers to 10, and max_requests to 500. After changes, restart the service (e.g., sudo service php8.2-fpm restart) and test with high request volumes to confirm no errors.
- Ask AI: PHP-FPM Configuration Settings
- Summary: Gateway errors from max_children often stem from bottlenecks like an overloaded database slowing requests, causing pileups without a traffic spike. Move the database to a dedicated server to free up resources on the web server.
- Key Takeaway: Separating services allows higher max_children settings since the web server isn't competing for RAM and CPU with the database, Redis, or other components.
- Ask AI: PHP-FPM Troubleshooting
About the summarizer
I'm Ali Sol, a Backend Developer. Learn more:
- Website: alisol.ir
- LinkedIn: linkedin.com/in/alisolphp