search
HomeBackend DevelopmentPHP TutorialHow to configure php.ini and perform PHP performance tuning?

How to configure php.ini and perform PHP performance tuning?

Apr 08, 2022 am 09:18 AM
php.iniphp performance tuning

How to perform PHP performance tuning? The following article will introduce you to some methods of configuring php.ini to see how to maximize PHP performance? I hope to be helpful!

How to configure php.ini and perform PHP performance tuning?

PHP used in production environments needs to be optimized to allow PHP itself to perform better. In addition to writing PHP code, you must also configure php.ini . Below we will explain the configuration tuning of php.ini from the aspects of memory, file upload, session buffer output, and real path cache.

Memory

Default setting

memory_limit = 128M

The maximum memory that can be used by a single process. This value can be set from Consider the following points:

  • Type of application. If it is a memory-intensive application, you can increase this value;

  • The average memory consumed by a single PHP process. This value can be averaged by running the same script multiple times;

  • How many php-fpm processes can it afford; this value is equal to the total allocated memory divided by the average memory consumed by a single PHP process

File upload

Default settings

file_uploads = On
max_file_uploads = 20
upload_max_filesize = 2M
max_execution_time = 30 值 为 0 代表没有限制
  • Set max_file_uploads to determine how many files are allowed to be uploaded at the same time;

  • Set upload_max_filesize to determine the maximum value for each file upload;

  • If it is a long-term task, try to use a queue to process it, so the value of max_execution_time can be shortened appropriately;

Note that the web server can also set the file upload size and timeout, not just the php.ini settings;

Session

PHP's session is saved on the hard disk by default

session.save_handler = files

In actual applications, the session should be saved in memory. You can use Memcached or Redis. There are two main benefits of doing this:

  • Increase speed;

  • It helps with later expansion. If the session data is stored on the hard disk, It is not convenient to add additional servers. If the session data is stored in Memcached or Redis, any distributed PHP-FPM server can access the session data.

You can install the memcached extension through PECL and set the default save_handler to memcached

session.save_handler = 'memcached'
session.save_path = '127.0.0.1:11211'

Buffered output

Default value

output_buffering = 4096

Delivering content to the visitor's browser in fewer fragments can reduce the total number of HTTP requests. Therefore, we need to let PHP buffer the output. By default, PHP has enabled the output buffering function. PHP buffers 4096 bytes of output before sending the content to the web server.

Note: If you want to modify the output buffer size, make sure to use a value that is a multiple of 4 (32-bit systems) or 8 (64-bit systems).

Real path cache

Default value

realpath_cache_size = 4M
realpath_cache_ttl = 120

PHP will cache the file path used by the application, so that each When you include or import a file, you no longer need to constantly search for the include path. This cache is called the real path cache. If you are running a large PHP file (such as the Composer component) and use a large number of files, increase the number of PHP real path caches. size for better performance.

Recommended: "PHP Video Tutorial"

The above is the detailed content of How to configure php.ini and perform PHP performance tuning?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:微信公众号-PHP自学中心. If there is any infringement, please contact admin@php.cn delete
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!