使用 WordPress 時間比較長的朋友很可能會遇到這樣的問題,

某一天,你的主機空間商突然給你一封郵件,告訴你你的網站資源佔用太高,

所以你的空間被暫停了,請你處理之後再幫你開通。

這樣的問題對於像我們這樣對技術並不特別瞭解的人來説,會直接不知所措。

所以,在這裏,我把所有可能造成 WordPress 資源佔用過高的因素進行了總結。

希望對你有所幫助。

1 、 WordPress 插件的問題

WordPress 的主程序是設計的非常強健的,一般來説,不會有什麼問題,但插件就不一樣了。

由於 WordPress 是一個開源的程序系統,所以誰都可以為它編寫插件,但各種各樣的插件,並不一定能保證程序的質量,特別是有的插件很可能已經很長時間沒有更新,導致跟最新的 WordPress 版本並不兼容,所以它們很有可能導致主機資源佔用過高。

所以,如果你的主機資源佔用過高,第一個要檢查的就是你使用了哪些插件,把沒用的和可能沒用的插件都刪除掉,再試試看。而且以後注意儘量少用插件,特別是來源不明的插件。

2 、網站本身流量太大

WordPress 本身是一個博客程序
,但如果你把它當做 CMS 系統來用的話,可能網站本身流量就非常巨大,這樣的情況下,也很可能會導致主機資源佔用過高。這時候,你可以嘗試使用 WP
Super
Cache 插件,它會把所有的頁面進行靜態化處理,對本身流量巨大的網站來説,會顯著降低主機資源佔用。但請注意,對一般的小網站來説,請不要使用這一類
的緩存插件,否則得不嘗失。

3 、定時類插件

這一點可能很多人都沒注意過,WordPress 有很多有名的插件都在使用定時類插件,比如 WP-DB-Backup 插件之類的備份插件,都有定時
備份的功能。但我要説的是,儘量不要使用定時任務的功能,因為不當的定時任務可能會導致死鎖,從而導致主機資源佔用過高。具體的技術細節我也沒有深究過,
但 WordPress 教程網以前也經歷過這樣的問題,下面是主機商發給我的信件,其中的 wp-cron.php 就是處理定時任務的。

This message is to advise you of a temporary block placed
on your account. This account was found to be consuming an inordinate
amount of processor time, to the point of degrading overall system
performance. While we do limit each account to no more than 25% of a
system's CPU in our terms of service, we do not actively disable
accounts until they greatly exceed that number, which is what happened
in this case.

Requests to this scripts under this account may become degraded by
limiting the abilty for scripts to run for a limited amount of time, or
if the issue persists, we may be forced to restrict how fast processes
can be spawned until the issue has been resolved.

We recommend taking steps to reduce the overall CPU usage for the
account, which may be as simple as generating a flat HTML page for
popular content, or enabling caching that is available through many
popular scripts, or disabling high CPU usage features such as searches
or Ajax refreshes. Although we may not be able to help in all cases, we
would be more than happy to assist if you are unable to determine any
cause, or if you need help interpreting any of the information.

CPU seconds used in the past hour: 2784.30999999998, 78% CPU

Current Site Requests:
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343898872.41504096984863281250
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343938404.43561100959777832031
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343938408.42049503326416015625
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343938410.08629703521728515625
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343938411.93777894973754882812
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343940419.26733207702636718750
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343940421.87949395179748535156
174.120.152.98 wpcourse.com /wp-cron.php?doing_wp_cron=1343940427.10176396369934082031

4 、 WordPress 版本的問題

最後要説的就是,儘量讓你的 WordPress 更新到最新版本,因為 WordPress 全球使用的人數實在是很多,所以同樣有很多黑客之類的人在想
方設法的找 WordPress 的漏洞,每次 WordPress 更新都會修復一些可能的漏洞,所以,更新到最新版本才能避免潛在的漏洞暴露在別有用心的人面
前。

今天先説到這裏,如果有漏掉的歡迎補充。