PHP Configuration Parameters

Source: Internet
Author: User
Tags fpm http 200 php language php error

PHP uses two more important configuration files:
    • php.ini: determines the environment in which the PHP language runs, supports extended modules, and configures the development environment. (paths typically located in/etc/php.ini or/usr/local/php/etc/php.ini)
    • php-fpm.conf: The Process Control Manager configuration file, which controls the number of php-cgi processes, resident memory, increases the response rate of the Web service, and the PHP-CGI runtime loads the two configuration files.
First, php.ini configurationMax_execution_time = 300 # maximum allowable execution time per script, in seconds. This parameter helps prevent inferior scripts from endlessly consuming server resources
Max_input_time = 300 # Maximum allowable time for each script to receive input data (POST, GET, upload), in seconds
Memory_limit = 256M # Sets the maximum number of bytes of memory that a script can request, which helps prevent inferior scripts from consuming all the memory on the server

#以下四项是与错误日志有关的设置
error_reporting = E_error
Display_startup_errors = On
Error_log =/home/web/logs/php_error.log
Log_level = Debug
File_uploads = on # Whether HTTP file uploads are allowed
Post_max_size = 8M #PHP The maximum length of post data accepted. This setting also affects file uploads. To upload a large file, the value must be greater than "upload_max_filesize", if the configuration script activates the memory limit, "Memory_limit" will also affect the file upload, generally speaking, "memory_limit" should be more than "post_max_size" Be big.
upload_max_filesize = 6M # maximum size allowed for uploaded files
Session.save_handler = Redis # handler for saving/retrieving data, default file (files), now modified to Redis
Session.cookie_httponly = true # turns on the HttpOnly attribute of the global cookie, adding security
Extension_dir =/usr/lib64/php/modules #扩展库的位置, demo environment is/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525 /

#配置文件中需要包含以下扩展库
Extension = blitz.so
Extension = memcache.so
Extension = redis.so

Second, php-fpm.conf configurationPID = Run/php-fpm.pid #pid设置, default in the installation directory of Var/run/php-fpm.pid, it is recommended to turn on error_log = Log/php-fpm.log #错误日志, the default in the installation directory var/log/ Php-fpm.log log_level = Notice #错误级别. The available levels are: alert (which must be processed immediately), error (Error condition), warning (warning condition), notice (general important information), debug (debug information). Default: Notice.php_flag[display_errors] = off # whether to display PHP error messages, no configuration on the server Emergency_restart_threshold = 60
Emergency_restart_interval = 60s #表示在emergency_restart_interval所设值内出现SIGSEGV或者SIGBUS错误的php-cgi process number if more than Emergency_ Restart_threshold, PHP-FPM will be gracefully restarted. These two options generally leave the default values.
Process_control_timeout = 0 #设置子进程接受主进程复用信号的超时时间. Available units: s (seconds), M (min), H (Hours), or D (day) default units: s (seconds). Default value: 0.daemonize = yes #后台执行fpm, the default is yes, if for debugging you can change to No. In FPM, you can use different settings to run multiple process pools. These settings can be set individually for each process pool.
Listen = 127.0.0.1:9000 #fpm监听端口, that is, the address of the PHP processing in Nginx, the general default value can be. The available formats are: ' Ip:port ', ' Port ', '/path/to/unix/socket '. Each process pool needs to be set. Listen.backlog = 1 #backlog数, 1 means unrestricted, determined by the operating system, and this line is commented out. Backlog meaning reference: http://www.cnblogs.com/shengshuai/p/4285946.htmllisten.allowed_clients = 127.0.0.1 #允许访问FastCGI进程的IP, Set any to No limit IP, if you want to set the other host's Nginx can also access this FPM process, listen to set the cost of the IP can be accessed. The default value is any. Each address is separated by commas. Allows any server to request a connection if it is not set or is empty
Listen.owner = www
Listen.group = www
Listen.mode = 0666
#unix socket Settings option, if accessed using TC, Comment here.

user = www
Group = www
#启动进程的帐户和组

PM = Dynamic #对于专用服务器, PM can be set to static. How to control child processes, options are static and dynamic. If Static is selected, the number of fixed child processes is specified by Pm.max_children. If dynamic is selected, it is determined by the following argument: Pm.max_children #, maximum number of child processes
Pm.start_servers #, number of processes at startup
Pm.min_spare_servers #, guarantees the minimum number of idle processes, and creates a new child process if the idle process is less than this value
Pm.max_spare_servers #, guarantees the maximum number of idle processes, and cleans up if the idle process is larger than this value
Pm.max_requests = #设置每个子进程重生之前服务的请求数. is useful for third-party modules that may have a memory leak. If set to ' 0 ', the request is always accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0.pm.max_requests = #max_requests参数配置不当, may cause intermittent 502 errors. Pm.status_path =/status #FPM状态页面的网址. If not set, the status page cannot be accessed. Default value: None. The Munin monitor uses the Ping.path =/ping #FPM监控页面的ping网址. If not set, the ping page cannot be accessed. This page is used to externally detect whether FPM is alive and can respond to requests. Note that you must start with a slash (/). Ping.response = Pong #用于定义ping请求的返回相应. Returns the Text/plain format text for HTTP 200. Default value: Pong.
Request_terminate_timeout = 0 #设置单个请求的超时中止时间. This option may be useful for scripts in php.ini settings where ' Max_execution_time ' is not aborted for some special reason. Set to ' 0 ' for ' Off '. You can try changing this option when a 502 error occurs frequently. The value of Request_terminate_timeout, if set to 0 or too long, can cause file_get_contents resource problems.
If the remote resource requested by file_get_contents is too slow, file_get_contents will remain stuck there and will not time out. We know that php.ini inside Max_execution_time can set the maximum execution time for PHP scripts, but in php-cgi (PHP-FPM), this parameter does not work.     The real ability to control the maximum execution time of a PHP script is the request_terminate_timeout parameter in the php-fpm.conf configuration file. The default value for Request_terminate_timeout is 0 seconds, meaning that the PHP script will continue to execute. This way, when all the php-cgi processes are stuck in the file_get_contents () function, the nginx+php webserver can no longer process the new PHP request, and Nginx will return "502 bad Gateway" to the user. To modify this parameter, it is necessary to set the maximum execution time for a PHP script, but the symptom is not a cure. For example, to 30s, if file_get_contents () to get a slow page content, which means that 150 php-cgi process, only 5 requests per second, WebServer also difficult to avoid "502 bad Gateway." The workaround is to set the request_terminate_timeout to 10s or a reasonable value, or to add a timeout parameter to file_get_contents.
$ctx = stream_context_create (Array (
' http ' = = Array (
' Timeout ' = 10//Set a time-out in seconds
)
));

file_get_contents ($str, 0, $ctx);
Request_slowlog_timeout = 10s #当一个请求该设置的超时时间后, the corresponding PHP call stack information is fully written to the slow log. Set to ' 0 ' means ' Off ' Slowlog = log/$pool. Log.slow #慢请求的记录日志, with request_slowlog_timeout using Rlimit_files = 1024x768 #设置文件打开描述符的rlim it constraints. Default: System-defined value default open handle is 1024, can be viewed using ULIMIT-N, ulimit-n 2048 modified. Rlimit_core = 0 #设置核心rlimit最大限制值. Available values: ' Unlimited ', 0, or positive integer. Default value: System-defined value. chroot = #启动时的Chroot目录. The defined directory needs to be an absolute path. If not set, Chroo is not used. ChDir = #设置启动目录, which is automatically chdir to the directory at startup. The defined directory needs to be an absolute path. Default value: Current directory, or/directory (chroot) Catch_workers_output = yes #重定向运行过程中的stdout和stderr到主要的错误日志文件中. If not set, stdout and stderr will be redirected to/dev/null according to the FASTCGI rules. Default value: Empty.

PHP Configuration Parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.