Home php教程 php手册 优化php参数,加快WordPress速度

优化php参数,加快WordPress速度

Jun 06, 2016 pm 08:11 PM
php wordpress optimization accelerate parameter this speed

这个博客陆陆续续使用过一些美国的VPS,但访问速度一直不能让我满意,使用17CE测试的时候,全国的打开速度普遍在4-10秒左右,原因不明。也曾见过有些WordPress用着美国的空间,没装WP Super Cache等缓存插件,打开速度却维持在2秒左右,让我觉得,自己在优

这个博客陆陆续续使用过一些美国的VPS,但访问速度一直不能让我满意,使用17CE测试的时候,全国的打开速度普遍在4-10秒左右,原因不明。也曾见过有些WordPress用着美国的空间,没装WP Super Cache等缓存插件,打开速度却维持在2秒左右,让我觉得,自己在优化这方面简直是太菜了。。

今天闲来无事,把Godaddy的免费空间安装了WordPress,拿17ce测试了一下,全国范围的打开速度在2-4秒左右,觉得有些不可思议。论性能,肯定是VPS要超出虚拟主机很多,为什么Godaddy的虚拟主机速度可以这么快……

我把Godaddy的免费空间上传了一个探针,仔细观察了一下,除了CPU、内存很大之外,我发现没有安装Zend Optimizer这个最基本的PHP加速器,当然,像memcache,eAccelerator等肯定也没有。比较奇怪的是发现有几个PHP的参数,跟lnmp一键安装包里面差距挺大。比较显著的是如下两个参数:

max_execution_time:翻译过来就是php脚本的最大执行时间,Godaddy家默认是30秒,但lnmp一键包默认是300秒
memory_limit:这个我的理解为每个php脚本的内存占用限制,但网络上有的说法是所有PHP脚本的内存总限制。Godaddy家默认是64M,但lnmp一键包默认是128M

然后就对比着优化了下,后来发现速度还不错,VPS和Godaddy免空的访问速度基本一样了。这里我给诸位使用lnmp一键安装包的朋友们一个优化方案:

1,修改/usr/local/php/etc/php.ini

max_execution_time = 30
memory_limit = 64M    ; 如果内存太小,也可设置成32M~48M
post_max_size = 10M   ; bluehost使用此值
upload_max_filesize = 10M  ; bluehost使用此值
……
disable_functions = ……    ;去掉其中的scandir和fsocketopen,保证WordPress的功能正常
Copy after login

2,修改/usr/local/php/etc/php-fpm.conf

15   
#256M内存的VPS建议保持默认的5,512内存的建议改为10,1G内存的建议改到20左右
……
60s    #改为60左右
Copy after login

别忘记执行service php-fpm reload重启一下php服务。

当你设置完,可能会出现如下的错误:
Fatal error: Out of memory (allocated xxxxxxx) (tried to allocate xxxx bytes)……
一看上去就是内存超限导致的,我的理解是,跟memory_limit和max_children的值有关。前者指定每个php脚本能占用的最大内存,而后者指定了可以同时运行多少php脚本。根据这个原因,只要随便改小其中一个值即可。

很多人还纠结是否应该安装lnmp一键包里的memcache和eAccelerator,我认为,eAccelerator可以安装,打开速度大约能提升1-2秒左右;至于memcache,这个东西是用来缓存数据库的,如果你的VPS是SSD硬盘,那么读取和写入的速度本来就很快,那完全没有安装的必要。如果是普通机械硬盘,那还是安装吧。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

What are the plugins for wordpress blocking ip What are the plugins for wordpress blocking ip Apr 20, 2025 am 08:27 AM

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to write a header of a wordpress How to write a header of a wordpress Apr 20, 2025 pm 12:09 PM

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

How to cancel the editing date of wordpress How to cancel the editing date of wordpress Apr 20, 2025 am 10:54 AM

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

What to do if there is an error in wordpress What to do if there is an error in wordpress Apr 20, 2025 am 11:57 AM

WordPress Error Resolution Guide: 500 Internal Server Error: Disable the plug-in or check the server error log. 404 Page not found: Check permalink and make sure the page link is correct. White Screen of Death: Increase the server PHP memory limit. Database connection error: Check the database server status and WordPress configuration. Other tips: enable debug mode, check error logs, and seek support. Prevent errors: regularly update WordPress, install only necessary plugins, regularly back up your website, and optimize website performance.

WordPress website account login WordPress website account login Apr 20, 2025 am 09:06 AM

To log in to a WordPress website account: Visit the login page: Enter the website URL plus "/wp-login.php". Enter your username and password. Click "Login". Verification Two-step Verification (optional). After successfully logging in, you will see the website dashboard.

How to change the head image of the wordpress theme How to change the head image of the wordpress theme Apr 20, 2025 am 10:00 AM

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

See all articles