我的舊貼文 WordPress es un CMS lento 的英文版 - 2014
我不只一次陷入爭論:WordPress 慢嗎?好吧,當附加到 WordPress 的人的唯一答案是有很多訪問量的網站使用它並且它們的性能是最佳的時,這並沒有太大的爭論。這些人似乎忘記了,如果在功能強大的機器上“運行”,即使冒泡排序演算法對於過大的樣本也能表現良好。然而,如果我們考慮其計算複雜性,這並不意味著它一定是一種有效的演算法(事實上並非如此)。 WordPress 也會發生同樣的情況。考慮到相同數量的信息,它將需要比其他 CMS 更強大的託管。不僅如此,正如我們將看到的,無論是否有大量訊息,WordPress 本質上都很慢。
這並不代表 WordPress 不好。事實並非如此。就像汽車一樣,速度並不是一切。 CMS 領域也是如此。事實上,我的許多網路專案都是用它建構的。然而,每個項目都是不同的,因此,您需要明智地選擇最好的工具,而不是出於執著。
由於我是技術人員,所以我的論點將基於技術面。特別是當我了解到 WordPress 由於其設計而緩慢時。我邀請任何不同意的人發表評論並說明他們的理由。
一切盡在一張桌子上
在為 Web 專案設計資料庫架構時,會出現一個問題:是追求實用性還是追求效率。就 WordPress 而言,他們選擇了實用性,並將帖子、自訂帖子、資源和版本全部分組在一個表中:wp_posts。此操作的優點是簡化程式碼和搜尋(儘管這是 WordPress 難以解決的另一個問題,正如我們將在另一篇文章中看到的),但缺點是,它大大降低了 WordPress 的效率。一些例子可以讓這一點更清楚:
如果我們有 500 個帖子,每個帖子都有四個不同的修訂版(當前的一個和另外三個),就好像我們正在處理 2,000 個帖子。
如果我們在 WooCommerce 中有 500 種產品,並且每種產品都有一張特色圖片,並且產品庫中有四張,那麼就好像我們的 CMS 必須處理 3,000 種產品。
如果我們有一個包含35 個頁面和35 個選單項目的小型網站,無論是外部鏈接還是內部鏈接,我們的內容管理器都會像有70 個頁面一樣工作,因為每個選單項都算是我們CMS 中的一個條目或頁面。在此範例中,這可能看起來不多,但它顯示了影響效能的另一個因素。
如果您有 500 種四種語言的產品,您的 WordPress 將像處理 2,000 種產品一樣運作。
現在,讓我們總結一下現實世界的範例:如果您有一個包含500 個產品的網站,每個產品都有一個特色圖像、四個產品圖庫圖像和一個包含技術資訊的PDF,而該網站還有一個包含200 個條目的博客,每個條目都有各自的特色圖片。如果您的網站也支援三種語言,並且設定為每個貼文僅允許兩次修訂,則 WordPress 每次查詢資料庫時都必須搜尋超過 5,500 個項目。我忽略了其他因素,例如選單項目、頁面和自訂貼文。建議:
將修訂數量限制為兩次或完全停用它們:
// Limit revisions to two: define('WP_POST_REVISIONS', 2); // Completely disable revisions: // define('WP_POST_REVISIONS', false);
- 不時刪除所有修訂。您可以透過執行以下 SQL 查詢來完成此操作:
DELETE a, b, c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';
節約網站上的圖片。請勿將不會使用的圖像新增至您的 CMS。
除非必要,否則避免使用多個選單。刪除您不打算使用的選單項目。
如果您沒有其他選擇,因為您的客戶堅持使用 WordPress 進行中型或大型項目,請嘗試建立輔助表以盡可能減輕 wp_posts 的負載。
你的 WordPress 患有老年癡呆症
WordPress 不惜一切代價尋求靈活性,甚至以犧牲速度為代價。也許是因為它一開始只是一個部落格系統,在這種情況下,如此大的靈活性不會造成太大的傷害。然而,當我們開始使用它作為 CMS 時,這種靈活性導致的效能問題開始出現。
Let me give you some bad news: your content manager has Alzheimer’s. It forgets everything from one request to another. You will have to repeat each time which custom posts, sidebars, or menus you are going to use. There is no other choice because it forgets. That's why, for example, if you want to add an entry to the admin menu, you will have to tell it every time it is to be displayed. Yes, it offers enormous flexibility, but it forces PHP and the CMS to process the same thing repeatedly, resulting in a loss of efficiency. The same thing happens with plugins, which is why many plugins can significantly slow down your website. It’s not because of the plugin system itself (which is magnificently designed and programmed) but because plugins have to declare the same information repeatedly, forcing WordPress to go through them entirely with every request.
A performance-focused CMS would have done it differently. For example, by having the theme declare during activation what sidebars, custom posts, or other elements it needs. WordPress would register this information and adjust internally. The same could be applied to plugins. But, as mentioned earlier, such an approach would significantly reduce the CMS's flexibility, which is not desirable.
Tips:
Limit the number of plugins.
Choose minimalist themes that only have what you need.
You might be advised to use a cache plugin; I don't. Only use one if your website is extremely slow and do so with caution. I will discuss this in another post (edit: now available: Don’t Use Cache Plugins with WordPress, but basically, it’s because you will disable all of WordPress’s internal workings based on hooks. That is, you will force WordPress to work in a way that is not intended.
Everything Always Available
As almost everyone knows, WordPress started as a blogging system based on a previous system. It wasn't designed for large projects, which is why its design leaned toward simplicity. No classes, just functions. As with any design aspect, this doesn’t have to be a bad thing (just ask those using desktops built with GTK) unless you are looking for flexibility. Then, the headaches begin.
If you come from the PHP world, you might be surprised that with WordPress, you don’t have to use "require," "include," or "namespace." This is easy to understand: WordPress always loads its entire arsenal of libraries. Yes, always, whether you use them or not. When you combine this with its memory issues, well... that's a lot of code to read with every request. But, of course, this is all for flexibility. You can use a core function without having to include a file that might change names or paths tomorrow.
Since PHP 5.6, there is full support for function namespaces. Maybe this is a solution for WordPress. But in that case, they will have to make the difficult decision of breaking backward compatibility. I don't know what they will do.
There’s nothing you can do to improve this, as it’s part of WordPress’s design. All you can do is your part: make sure your code doesn't follow this path. If you decide to do so, here are my tips:
- Create anonymous functions for "actions" that are nothing more than includes to external files where you keep your code. This way, if the action never triggers, PHP won’t have to parse all the code. Example:
add_action('admin_init', function() { include(__DIR__ . "/zones/panel/init.php"); }); add_action('admin_menu', function() { include(__DIR__ . "/zones/panel/menu.php"); });
- For widgets, shortcodes, and filters, use classes with namespaces. Also, make sure these classes are instantiated using autoloading.
// It's better to use: spl_autoload_register() function __autoload($classname) { $file = str_replace('\\', DIRECTORY_SEPARATOR, $classname); include_once(BASE_PATH . $file . '.php'); } add_shortcode('block', array('misshortcodesBlock', 'load')); //... my other shortcodes, filters, and widgets...
In summary, we have seen that WordPress's design principles are simplicity and flexibility, but in a way that sacrifices efficiency. It is essential to understand that no development tool is good for everything. If someone presents it that way, they are either misleading you or selling you a Swiss army knife that is good for nothing.
WordPress struggles with speed, but for showcase websites, this is not something to worry about. However, for websites where the business relies on the web, or for sites with a lot of traffic, alternative options should be considered. Still, if we choose WordPress for its ease of use and flexibility, we must compensate by investing in good hosting, being very careful with the selection of plugins, and using a high-quality theme tailored to our needs.
以上是WordPress 是一個緩慢的 CMS的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Laravel使用其直觀的閃存方法簡化了處理臨時會話數據。這非常適合在您的應用程序中顯示簡短的消息,警報或通知。 默認情況下,數據僅針對後續請求: $請求 -

PHP客戶端URL(curl)擴展是開發人員的強大工具,可以與遠程服務器和REST API無縫交互。通過利用Libcurl(備受尊敬的多協議文件傳輸庫),PHP curl促進了有效的執行

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显著减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP日誌記錄對於監視和調試Web應用程序以及捕獲關鍵事件,錯誤和運行時行為至關重要。它為系統性能提供了寶貴的見解,有助於識別問題並支持更快的故障排除

您是否想為客戶最緊迫的問題提供實時的即時解決方案? 實時聊天使您可以與客戶進行實時對話,並立即解決他們的問題。它允許您為您的自定義提供更快的服務

文章討論了PHP 5.3中介紹的PHP中的晚期靜態結合(LSB),允許靜態方法的運行時間分辨率調用以更靈活的繼承。 LSB的實用應用和潛在的觸摸


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

禪工作室 13.0.1
強大的PHP整合開發環境

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SublimeText3漢化版
中文版,非常好用