Увеличение производительности WordPress: WP Super Cache и Lighttpd
Заканчивая цикл статей по mod_magnet и lighttpd стоит упомянуть настройку WP Super Cache. Данный плагин необходим для кэширования страниц WordPress, так как сам WordPress с этим справляется плохо. Как работает этот плагин? Существует несколько режимов, но я использовал два:
- Сохраняется отдельно страница блога (уже закэшированная) на диске в виде обычного HTML-файла. Этот файл и отдаётся при запросе. Следовательно отдаётся просто статика, а никаких новых вычислений делать не надо.
- Данный файл сжимается gzip и располагается рядом. Если браузер посетителя позволяет получить сжатую страницу, то она ему и отдаётся.
Вся проблема как всегда упёрлась в lighttpd, так как решение под Apache, конечно, уже есть. Тем не менее я нашёл и оптимизировал под WordPress MU.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | function serve_html(cached_page) if (lighty.stat(cached_page)) then lighty.env["physical.path"] = cached_page print("Serving cached page: " .. cached_page) return true else return false end end function serve_gzip(cached_page) if (lighty.stat(cached_page .. ".gz")) then lighty.header["Content-Encoding"] = "gzip" lighty.header["Content-Type"] = "" lighty.env["physical.path"] = cached_page .. ".gz" print("Serving gzipped page: " .. cached_page .. ".gz") return true else return false end end attr = lighty.stat(lighty.env["physical.path"]) if (not attr) then i, j = string.find(lighty.env['uri.path'], "/download/") k, m = string.find(lighty.env['uri.path'], "/files/") t, f = string.find(lighty.env['uri.path'], "/wp-") e, s = string.find(lighty.env['uri.path'], ".php") if (i == 1 and j == 10 and string.len(lighty.env['uri.path']) > 10) then id = string.sub(lighty.env['uri.path'], j + 1) lighty.env["uri.path"] = "/wp-content/plugins/download-monitor/download.php" lighty.env["physical.rel-path"] = lighty.env["uri.path"] lighty.env['uri.query'] = "id=" .. id elseif (k) then file = string.sub(lighty.env['uri.path'], m + 1) lighty.env["uri.path"] = "/wp-content/blogs.php" lighty.env["physical.rel-path"] = lighty.env["uri.path"] lighty.env['uri.query'] = "file=/" .. file elseif (t) then path = string.sub(lighty.env['uri.path'], t) lighty.env["uri.path"] = path lighty.env["physical.rel-path"] = lighty.env["uri.path"] elseif (e) then g, v = string.find(lighty.env['uri.path'], "/", 2) path = string.sub(lighty.env['uri.path'], g) lighty.env["uri.path"] = path lighty.env["physical.rel-path"] = lighty.env["uri.path"] else lighty.env["uri.path"] = "/index.php" lighty.env["physical.rel-path"] = lighty.env["uri.path"] end lighty.env["physical.path"] = lighty.env["physical.doc-root"] query_condition = not (lighty.env["uri.query"] and string.find(lighty.env["uri.query"], ".*s=.*")) user_cookie = lighty.request["Cookie"] or "no_cookie_here" cookie_condition = not (string.find(user_cookie, ".*comment_author.*") or string.find(user_cookie, ".*wordpress.*") or string.find(user_cookie, ".*wp-postpass_.*")) if (query_condition and cookie_condition) then accept_encoding = lighty.request["Accept-Encoding"] or "no_acceptance" cached_page = lighty.env["physical.doc-root"] .. "/wp-content/cache/supercache/" .. lighty.request["Host"] .. lighty.env["request.uri"] .. "/index.html" cached_page = string.gsub(cached_page, "//", "/") if (string.find(accept_encoding, "gzip")) then if not serve_gzip(cached_page) then serve_html(cached_page) end else serve_html(cached_page) end end end |
И всё работает замечательно. Ссылка по теме:
Коммент.(0)