Apa itu memory_limit PHP?

PHP memory_limit adalah jumlah maksimum memori server yang dapat digunakan oleh setiap skrip PHP.

Dokumentasi PHP resmi menjelaskan hal ini secara lebih rinci.

"Ini menetapkan jumlah maksimum memori dalam byte yang diizinkan untuk dialokasikan oleh skrip. Ini membantu mencegah skrip yang ditulis dengan buruk memakan semua memori yang tersedia di server."

Nilai default untuk memori PHP adalah 128M. Ini dapat dinaikkan jika aplikasi atau situs web membutuhkan lebih banyak memori.

Ketika skrip melebihi batas memori yang telah ditetapkan untuk server, error akan mirip seperti ini:

Fatal error: Allowed memory size of x bytes exhausted (tried to allocate x bytes) in /example/php/script PHP Fatal error: Out of memory (allocated x) (tried to allocate x bytes) in /example/php/script

Perlu diketahui bahwa jika kamu menggunakan VPS, maka server kamu akan memiliki memori fisik. Kamu perlu melakukan konfigurasi parameter memory_limit agar penggunaannya optimal.


The PHP memory_limit is the maximum amount of server memory that each PHP script can use. 

The official PHP documentation explains this in greater detail. 

"This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts from eating up all available memory on a server.”

The default value for PHP memory is 128M. This can be raised if an application or website needs more memory. 

When a script exceeds the memory limit that's been set for the server an error similiar to the following will be logged. 

Fatal error: Allowed memory size of x bytes exhausted (tried to allocate x bytes) in /example/php/script PHP Fatal error: Out of memory (allocated x) (tried to allocate x bytes) in /example/php/script

Be aware that if you're on a Managed VPS then your server has a physical memory limit. You should optimize your code if the memory_limit parameter is already set to its maximum.

 

  • 0 משתמשים שמצאו מאמר זה מועיל
?האם התשובה שקיבלתם הייתה מועילה

מאמרים קשורים

Mengubah versi PHP pada folder, subdomain, atau domain tertentu

ITPanel mendukung Multi-PHP version dengan cara menambahkan kode versi PHP yang akan digunakan...