Kamis, 03 Februari 2022

OPTIMIZE PHP-php.ini revenu

 

How to Optimize the php.ini File for your Website

https://www.prestashop.com/en/blog/php-ini-file
June 27, 2013
  

The php.ini file is one of the most crucial server configurations. Web-hosts have a variety of specific configurations for their servers. In this article, I’ll explain what the php.ini file is and what specific settings you should pay close attention to in order to bypass common errors and optimize your online store or website.

What is the php.ini file and why should you care?

The php.ini file is a PHP server’s main configuration file. When your PHP server is first turned on or restarted, it reads the php.ini to load various settings and configurations. These settings control different server aspects like memory limits, data handling and file uploads.
Your php.ini file is located in your server’s root or public_html folder, not your PrestaShop files. Most hosting companies will allow you to access and change the php.ini file. If you can’t find it or do not have not access to it, contact your hosting company and they will work with you to change these settings.
It’s important to understand the php.ini file because its settings can be customized to solve common server-side errors and speed up your entire PrestaShop store. Let’s review some of the essential settings that you can change to optimize your online store.

Which settings are more important?

  • memory_limit = Maximum amount of memory a script may consume, in megabytes

Webhosts have default values regarding the amount of memory you are allowed on your account. PrestaShop 1.5 recommends 64mb as a minimum, which is very lightweight. However, if you have a more resource intensive store, you may need to change this value. This setting is especially important to consider if you are having a “Fatal Error: Allowed memory size” issue or if your Modules tab in your Back-Office is returning a blank white page.

Let’s increase this value to 128M. If you are still having problems with memory errors, increase the value to 256M to be safe. I’ve seen some extremely large resource intensive stores on dedicated hosting have as much as a 1-2GB of memory; it really depends on your store.
Find your php.ini file and search for “memory_limit”. Some shared hosts will have the default limit at 32M but most will have either 64M or 128M.
When you change it, the line in your php.ini file will look like this
“memory_limit = 128M”

---------------------------------------------------------------------------------------------------------

  • max_input_time = Maximum amount of time each script can wait for requested data, in seconds
  • max_execution_time = Maximum allowed execution time of each script, in seconds.

These two time limits are connected. The “max_input_time” setting controls how long a script can wait to receive data requested from the server while the “max_execution_time” controls how long a script can run on your server after the data has been received. Most hosts have the default setting value to 30 seconds each. As they are both connected, I recommend disabling the “max_input_time” and increasing the “max_execution_time” to 300 seconds.
The maximum execution time is a common limit that is exceeded. It’s better to change this value to something much higher as some special scripts need the extra time to execute and complete. These settings are especially important if you are performing resource intensive scripts like adding a large amount of combinations, backing up a database, importing a CSV file and regenerating images.
Find your php.ini file and search for “max_input_time” and “max_execution_time”. We will use the value -1 to disable the “max_input_time” and 300 to increase the “max_execution_time”.
When you change them, the lines in your php.ini file will look like this,
“max_input_time=-1;” and “max_execution_time=300;”

---------------------------------------------------------------------------------------------------------

  • upload_max_filesize: Maximum file size your server will allowed to be uploaded, in megabytes
  • post_max_size: Maximum data size allowed to uploaded, in megabytes

These two values are intertwined. They control the size of files and data that you are allowed to upload to your server. The post_max_size must be bigger or equal to the value of upload_max_filesize. These settings are especially important if you are having issues uploading large, high resolution pictures for your slideshow or products. Also, downloadable products like digital CD’s and large .pdf files will need to have these settings changed in order to upload them to your store.
Find your php.ini file and search for “upload_max_filesize” and “post_max_size”. By default these settings can be anywhere from 2-5 megabytes. Let’s change them to 25M.
When you change them, the lines in your php.ini file will look like this
“upload_max_filesize=25M;” and “post_max_size=25M;”

---------------------------------------------------------------------------------------------------------

  • max_input_vars: The maximum number of variable form elements that can be submitted to a single page.

The “max_input_vars” setting in the php.ini file is a relatively new option starting last year from PHP 5.3.9. It allows you to control the maximum number of form elements on a page. Some webpages have a large amount of forms/fields for administrative or page configuration purposes. In those cases, we need to increase the number of this value in order to properly view those pages. In PrestaShop, this setting is important if you are having trouble viewing, editing or saving translations in your Back-Office.
Find your php.ini file and search for “max_input_vars”. By default, most hosts have this limit set to 1000. To be safe, we’ll change it to 10000.
When you change it, the line in your php.ini file will look like this
“max_input_vars = 10000;”

[Technical Note: If your hosting provider has the “suhosin” php patch, you will need to change two more values to the same number. These values are
suhosin.get.max_vars = 10000;
suhosin.post.max_vars = 10000; ]

Piecing it all together

Let’s take a look at the summary of different settings we changed to bypass server-side errors and optimize your PrestaShop store’s efficiency.

  • memory_limit = 128M
  • max_execution_time=300;
  • max_input_time=-1
  • upload_max_filesize=25M;
  • post_max_size=20M;
  • max_input_vars=10000
  • suhosin.get.max_vars = 10000;
  • suhosin.post.max_vars = 10000;

Tidak ada komentar:

Posting Komentar