Home  >  Article  >  Backend Development  >  Summary of Fresh Round PHP Interview Questions

Summary of Fresh Round PHP Interview Questions

藏色散人
藏色散人forward
2021-07-27 16:33:143397browse

Related recommendations: "2021 PHP Interview Questions Summary (Collection)"

##PHP Interview Summary of the problem

Garbage collection mechanism

Each PHP variable exists in a structure called zval. In addition to the variable type and value, it also includes is_ref ( =true pointer variable, -false ordinary variable), refcount (the number pointing to this variable), when deleting an element causes refcount=0, this variable is deleted by the garbage collection mechanism

The following operations will cause refcount to never be is 0, which may lead to memory overflow

$a = array( 'one' );
$a[] =& $a;
unset($a);

Whenever refcount decreases by one, the variable is placed in the buffer area and waits for periodic recycling processing. Whenever the root buffer area is full (default 10000), it will be executed Recycling algorithm

FPM tuning

pm = dynamic : 灵活模式,子进程的数量是根据以下指令来动态生成的,默认是这个模式:
pm.max_children,//最大子进程数
pm.start_servers,//初始化启动进程数
pm.min_spare_servers,//最低闲置进程数
pm.max_sqare_servers//最高闲置进程数

pm = ondemand: dead fish mode, this mode will only start the child process after the request comes, almost every time The time to wait for starting a worker is more suitable for virtual host mode. pm.process_idle_timeout kills the child process after seconds

pm = static: Maximum horsepower mode, the number of child processes is determined by the pm.max_children command. It always operates as the largest child process, which consumes a lot of memory, but the response is very fast. If the server memory is very large, you can use this. If your server has more than 8G, one process is calculated as 20M, and the total of 100 processes is only 2G

Write more logs, it’s correct


Slow log

slowlog = /usr/local/var/log/php-fpm.log.slow
request_slowlog_timeout = 15s

Error log

error_log =  /usr/local/var/log/php-fpm.log

Access log

access.log = log/$pool.access.log
OPCACHE 代码=>AST抽象语法树=>生成opcode缓存 之后还可以优化
opcache.enable=1    //默认关闭
opcache.memory_consumption=512//最大内存空间,单位MB
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=32531//缓存脚本数量
opcache.validate_timestamps=0//0不校验文件变动,文件改动,需要手动清除opcache
opcache.validate_timestamps=0//1校验文件变动,
opcache.revalidate_freq=10 //校验文件的时间间隔
opcache.save_comments=1//保留注释,?注解要用到?
opcache.fast_shutdown=0
##PHP7.4+ 预加载文件
opcache.preload=/home/rawphp/preload.php
opcache.preload_user=odin

CGI, FASTCGI, PHPFPM, PHPCGI

CGI is a protocol that specifies the format of data transmitted by the server to dynamic scripts

FASTCGI improves the performance of CGI, starts a master process, and parses the php.ini file , when a request comes in, a worker process is directly copied out, and the request can be processed immediately, and pm.start_servers workers can also be started in advance to improve performance.

PHPFPM is a program that implements FASTCGI

PHPCGI is just a CGI handler that simply parses the request and returns the result. It does not have advanced functions such as process management.

The above is the detailed content of Summary of Fresh Round PHP Interview Questions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete