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);
FPM tuning
pm = dynamic : 灵活模式,子进程的数量是根据以下指令来动态生成的,默认是这个模式: pm.max_children,//最大子进程数 pm.start_servers,//初始化启动进程数 pm.min_spare_servers,//最低闲置进程数 pm.max_sqare_servers//最高闲置进程数
slowlog = /usr/local/var/log/php-fpm.log.slow request_slowlog_timeout = 15s
error_log = /usr/local/var/log/php-fpm.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!