简体   繁体   English

Magento FPC Cache使用用户组,wget,Lesti FPC热情

[英]Magento FPC Cache Warm with user groups, wget, Lesti FPC

I'm using Lesti FPC on a Magento site with 10 customer groups and a lot of categories/products. 我在Magento网站上使用Lesti FPC,有10个客户群和很多类别/产品。

I've created a shell script which reads the sitemap.xml and wget's each url overnight to build the cache of the site. 我创建了一个shell脚本,它读取sitemap.xml并在一夜之间wget每个url来构建站点的缓存。 This works great for guests but when a customer group user logs in, they are building the cache themselves (if they are the first of the day). 这对客人很有用,但是当客户组用户登录时,他们自己构建缓存(如果他们是当天的第一天)。

Does anyone know how to make a shell script that could simulate logging itself in and then trawl the site? 有谁知道如何制作一个shell脚本,可以模拟自己登录然后拖网站点? Is it even possible for a shell script to hold its own session/cookie information to remain logged in? 是否有可能shell脚本保留自己的会话/ cookie信息以保持登录状态? and if not, any other ideas? 如果没有,还有其他想法吗?

Many thanks 非常感谢

So thanks to some Googling and lots of trial and error, I've found a solution which I thought I'd share. 所以,多亏了一些谷歌搜索和大量的反复试验,我找到了一个我认为我会分享的解决方案。

You can use WGET to hold session/cookie information by saving and loading the cookies. 可以使用WGET通过保存和加载cookie来保存会话/ cookie信息。 Magento has it's own restriction as you need to establish a session cookie before you login or the script will be redirected to the 'enable-cookies' page rather than login, so here is the script; Magento有自己的限制,因为你需要在登录之前建立一个会话cookie,或者将脚本重定向到'enable-cookies'页面而不是登录,所以这里是脚本;

#!/bin/bash
# Establish a session and nab the cookie                   
 wget --save-cookies cookies.txt \
 http://www.yourmagentourl.co.uk/

# Post your user credentials to login and update the cookie
  wget --save-cookies cookies.txt \
  --load-cookies cookies.txt \
  --post-data 'login[username]=USERNAME&login[password]=PASSWORD' \
  http://www.yourmagentourl.co.uk/customer/account/loginPost/


# Load the cookie for each page you want to WGET to maintain the session
 wget --load-cookies cookies.txt \
 -p http://www.yourmagentourl.co.uk/some-category.html

That's the basis, so very easy to now load all the urls from a sitemap.xml and build the logged in versions of the cache. 这是基础,所以现在很容易从sitemap.xml加载所有url并构建缓存的登录版本。

Props to Grafista for a steer on saving cookie info. 向Grafista道具,以节省cookie信息。

Happy caching! 快乐缓存!

EDIT - AS PER REQUEST TO SHOW THE ORIGINAL CODE 编辑 - 根据要求显示原始代码

Here's the code to cycle through the sitemap and load each page to build the cache for guests. 这是循环遍历站点地图并加载每个页面以为guest虚拟机构建缓存的代码。 Save this as cachewarm.sh and create a cronjob to run it each night (dont forget to delete or expire your pagecache first) 将其保存为cachewarm.sh并创建一个cronjob以便每晚运行它(不要忘记先删除或过期你的pagecache)

#!/bin/bash
# Pixie Media https://www.pixiemedia.co.uk
# Use the sitemap and reload the Page Cache by accessing each page once
#

wget --quiet http://YOUR-URL.co.uk/sitemap.xml --output-document - | egrep -o "http://YOUR-URL.co.uk/[^<]+" | wget -q --delete-after -i -

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM