php realpath 缓存,PHP的Realpath Cache

PHP的缓存有很多种,包括输出缓冲(ob系列函数),opcode缓存(APC,eAccelerator,XCache等扩展实现),这些大家已经很熟悉了,接下来介绍一下一个不太被人注意的PHP缓存机制:realpath_cache。

介绍

require,require_once,include,include_once这四个语句(并非函数)大家经常会用到,如果用这类语句去包含文件 (相对路径)的话,那么PHP会去include_path所 指定的路径中去查找相关文件。一个应用中会存在大量的require_once语句调用,如果每次调用都去include_path中查找相应的文件,势 必会对应用的性能产生负面影响。为了避免这种负面效应产生的影响,PHPER们会使用文件的绝对路径来包含所需的文件,这样就减少了查询 include_path的次数。

其实,PHP自5.1.0起,就引入了RealpathCache。RealpathCache可以把PHP所用到文件的realpath进行缓存,以便PHP再使用这些文件的时候不需要再去include_path中查找,加快PHP的执行速度。

配置

realpath cache的配置项有两个,分别为realpath_cache_size和realpath_cache_ttl,可以在php.ini中进行修改:

; Determines the size of the realpath cache to be used by PHP. This value should

; be increased on systems where PHP opens many files to reflect the quantity of

; the file operations performed.

; http://php.net/realpath-cache-size

;realpath_cache_size = 16k

; Duration of time, in seconds for which to cache realpath information for a given

; file or directory. For systems with rarely changing files, consider increasing this

READ MORE

PHP-FPM配置

[global]

error_log = /usr/local/webserver/php/log/fpm_error.www.log

[www]

user = vapp_user_5i5j

group = vapp_user_5i5j

listen = 127.0.0.1:9000

pm = dynamic

pm.max_children = 350

pm.start_servers = 250

pm.min_spare_servers = 200

pm.max_spare_servers = 350

pm.max_requests = 3000

slowlog = log/$pool.log.slow

request_slowlog_timeout = 3s

request_terminate_timeout = 21

php_flag[display_errors] = off

php_admin_value[error_log] = /usr/local/webserver/php/log/fpm-php.www.log

php_admin_flag[log_errors] = on

php_admin_value[memory_limit] = 32M

备份

cp /usr/local/webserver/php/etc/php-fpm.conf /usr/local/webserver/php/etc/php-fpm.conf.bak

重启

ps aux | grep php-fpm | grep master | awk ‘{print$2}’| xargs kill -USR2

READ MORE

php8 openssl

简洁版:

问题1 :

No package ‘openssl’ found

执行2个命令 export OPENSSL_CFLAGS=/usr/local/Cellar/openssl@1.1/1.1.1n/include export OPENSSL_LIBS=/usr/local/Cellar/openssl@1.1/1.1.1n/lib

问题2:

ext/openssl/php_openssl.h:28:10: fatal error: ‘openssl/opensslv.h’ file not found export CPPFLAGS=-I/usr/local/Cellar/openssl@1.1/1.1.1n/include export LDFLAGS=-L/usr/local/Cellar/openssl@1.1/1.1.1n/lib

参考 https://blog.csdn.net/mouday/article/details/125469596 https://segmentfault.com/a/1190000040421959

详细

MacOS编译安装PHP8.0的时候报错如下:

No package ‘openssl’ found

检查是否安装

openssl version

# 或者
brew info openssl

# 未安装就安装
brew install openssl

如果已经安装还是报错,将PKG_CONFIG_PATH添加到环境变量中

# ~/.bash_profile

# pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

# openssl
export OPENSSL_LIBS="-L/usr/local/Cellar/openssl@1.1/1.1.1p/lib"
export OPENSSL_CFLAGS="-I/usr/local/Cellar/openssl@1.1/1.1.1p/include"

注意路径中的版本号可以不太一样

注册到pkgconfig中

# 查看 openssl 是否在 pkgconfig 中
pkg-config --list-all | grep openssl

# 如果不在pkgconfig,可以新建软链
cd /usr/local/Cellar/openssl@1.1/1.1.1p/lib/pkgconfig
ln -s `pwd`/openssl.pc /usr/local/lib/pkgconfig

https://segmentfault.com/a/1190000040421959

READ MORE

php8安装

./buildconf --force
./configure \
    --prefix=/usr/local/php \
    --with-curl \
    --with-gettext \
    --with-mysqli \
    --with-pear \
    --with-pdo-mysql \
    --with-xsl \
    --with-zlib \
    --enable-bcmath \
    --enable-fpm \
    --enable-mbregex \
    --enable-mbstring \
    --enable-opcache \
    --enable-pcntl \
    --enable-phpdbg \
    --enable-shmop \
    --enable-soap \
    --enable-sockets \
    --enable-sysvsem \
    --enable-shared \
    --enable-xml \
    --with-iconv=/Users/zuoerdong/local/libiconv-1.16 \
    --with-zlib \
    --with-zlib-dir=/Users/zuoerdong/local/zlib-1.2.11 \
    --with-openssl \
    --with-openssl-dir=/Users/zuoerdong/local/openssl-1.1.0g





export OPENSSL_CFLAGS=/Users/zuoerdong/local/openssl-1.1.0g/include
export OPENSSL_LIBS=/Users/zuoerdong/local/openssl-1.1.0g/lib
export CPPFLAGS=-I/Users/zuoerdong/local/openssl-1.1.0g/include
export LDFLAGS=-L/Users/zuoerdong/local/openssl-1.1.0g/lib

brew安装

brew update

切换php版本

brew link --overwrite --force php@8.2
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --enable-inline-optimization --enable-shared --enable-sockets --enable-opcache --enable-fpm --enable-bcmath --enable-zip --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mbstring --with-iconv=/usr/local/webserver/libiconv-1.16 --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl=/usr/local/webserver/curl-7.57.0 --with-openssl=/usr/local/webserver/openssl-1.1.0g --with-zlib=/usr/local/webserver/zlib-1.2.11 --with-libxml-dir=/usr/local/webserver/libxml2-2.9.7

READ MORE