Jumat, 15/11/2024 - 12:52 WIB
IndonesianArabicEnglishRussianGermanFrenchChinese (Simplified)JapaneseMalayHindi

TERBARU

TEKNOLOGITUTORIAL

How to Optimize PHP-FPM for High Performance

image_pdfimage_print

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user’s group
; will be used.
user = www-data
group = www-data
A quick look at the end of the snippet above solves the riddle of why the server process runs as www-data. If you’ve come across file permission issues when setting up your website, you’ve likely changed the owner or group of the directory to www-data, thus allowing the PHP process to be able to write into log files and upload documents, etc.

ADVERTISEMENTS
Kartu ATM di Rumah, Action Mobile di Tangan

Finally, we arrive at the source of the matter, the process manager (pm) setting. Generally, you’ll see the defaults as something like this:

ADVERTISEMENTS
Bank Aceh Syariah Mengucapkan Selamat Hari Pahlawan 10 November 2024
pm = dynamic
pm.max_children = 5
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 200

So, what does “dynamic” here mean? I think the official docs best explain this (I mean, this should already be part of the file you’re editing, but I’ve reproduced it here just in case it isn’t):

ADVERTISEMENTS
Memperingati 96 Tahun Sumpah Pemuda dari Bank Aceh Syariah
; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives. With this process management, there will be
;             always at least 1 children.
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
;  ondemand - no children are created at startup. Children will be forked when
;             new requests will connect. The following parameter are used:
;             pm.max_children           - the maximum number of children that
;                                         can be alive at the same time.
;             pm.process_idle_timeout   - The number of seconds after which
;                                         an idle process will be killed.
; Note: This value is mandatory.

So, we see that there are three possible values:

Berita Lainnya:
Jelajahi Peluang Taruhan yang Luar Biasa dengan Aplikasi 1Win
ADVERTISEMENTS
Selamat & Sukses atas Pelantikan Ketua DPRA, Wakil Ketua I DPRA dan Wakil Ketua II DPRA
  • Static: A fixed number of PHP processes will be maintained no matter what.
  • Dynamic: We get to specify the minimum and maximum number of processes that php-fpm will keep alive at any given point in time.
  • ondemand: Processes are created and destroyed, well, on-demand.

So, how do these settings matter?

Berita Lainnya:
Download Video HD di Tubidy Tanpa Kuota Meluber!
ADVERTISEMENTS
Pertemuan Tahunan Perbankan Syariah 2024

In simple terms, if you have a website with low traffic, the “dynamic” setting is a waste of resources most of the time. Assuming that you have pm.min_spare_servers set to 3, three PHP processes will be created and maintained even when there’s no traffic on the website. In such cases, “ondemand” is a better option, letting the system decide when to launch new processes.

ADVERTISEMENTS
Selamat Memperingati Hari Santri Nasional

On the other hand, websites that handle large amounts of traffic or must respond quickly will get punished in this setting. Creating a new PHP process, making it part of a pool, and monitoring it, is extra overhead that is best avoided.

Using pm = static fixes the number of child processes, letting maximum system resources to be used in serving the requests rather than managing PHP. If you do go this route, beware that it has its guidelines and pitfalls. A rather dense but highly useful article about it is here.

Final words

Since articles on web performance can spark wars or serve to confuse people, I feel that a few words are in order before we close this article. Performance tuning is as much about guesswork and dark arts as it is system knowledge.

1 2 3 4

Reaksi & Komentar

ثُمَّ قَسَتْ قُلُوبُكُم مِّن بَعْدِ ذَٰلِكَ فَهِيَ كَالْحِجَارَةِ أَوْ أَشَدُّ قَسْوَةً ۚ وَإِنَّ مِنَ الْحِجَارَةِ لَمَا يَتَفَجَّرُ مِنْهُ الْأَنْهَارُ ۚ وَإِنَّ مِنْهَا لَمَا يَشَّقَّقُ فَيَخْرُجُ مِنْهُ الْمَاءُ ۚ وَإِنَّ مِنْهَا لَمَا يَهْبِطُ مِنْ خَشْيَةِ اللَّهِ ۗ وَمَا اللَّهُ بِغَافِلٍ عَمَّا تَعْمَلُونَ البقرة [74] Listen
Then your hearts became hardened after that, being like stones or even harder. For indeed, there are stones from which rivers burst forth, and there are some of them that split open and water comes out, and there are some of them that fall down for fear of Allah. And Allah is not unaware of what you do. Al-Baqarah ( The Cow ) [74] Listen

Berita Lainnya

Tampilkan Lainnya Loading...Tidak ditemukan berita/artikel lainnya.
IndonesianArabicEnglishRussianGermanFrenchChinese (Simplified)JapaneseMalayHindi