优化 CentOS 上 ThinkPHP 的响应时间,可从服务器配置、PHP 代码、数据库和缓存策略等多个方向着手。具体建议如下:

若将 Nginx 用作 Web 服务器,可采取以下优化措施:
http {# 增加 worker 进程数worker_processes auto;worker_connections 1024;# 启用 Gzip 压缩gzip on;gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;# 缓存静态文件location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {expires 30d;add_header Cache-Control "public";}# 反向代 理设置server {listen 80;server_name yourdomain.com;location / {root /path/to/your/thinkphp/project;index index.php index.html index.htm;try_files $uri $uri/ /index.php?$query_string;}location ~ .php$ {fastcgi_pass unix:/tmp/php-cgi.sock;fastcgi_index index.php;include fastcgi.conf;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;}}}编辑 /etc/php-fpm.d/www.conf 文件,调整以下参数:
pm = dynamicpm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 35request_terminate_timeout = 30sconfig/app.php 中开启。'cache' => ['type' => 'file','path' => '/tmp/cache',],eval() 和 assert() 等开销较高的函数。应用若包含大量图片、CSS、JS 文件等静态资源,可考虑借助 CDN 加快这些资源的加载。
落实以上步骤后,应能明显缩短 CentOS 上 ThinkPHP 的响应时间。优化需要持续进行,并根据实际情况不断调整和改进。