在Docker中優(yōu)化PHP和數(shù)據(jù)庫的性能,可以采取以下措施:
pdo_mysql
、opcache
、mbstring
等必要的擴展,以提高數(shù)據(jù)庫連接和處理的效率。php.ini
文件中增加內(nèi)存限制,例如:memory_limit = 256M
max_execution_time = 30
opcache.enable = On
opcache.memory_consumption = 64
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 2
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_file_per_table = On
CREATE INDEX idx_name ON table_name(column_name);
version: '3'
services:
app:
image: php:7.4-fpm
ports:
- "9000:9000"
environment:
- DB_HOST=db
- DB_USER=user
- DB_PASS=password
volumes:
- ./app:/var/www/html
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: mydatabase
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
通過以上措施,可以在Docker環(huán)境中優(yōu)化PHP和數(shù)據(jù)庫的性能,提高應用的響應速度和穩(wěn)定性。