带有用户组,wget,Lesti FPC的Magento FPC Cache Warm [英] Magento FPC Cache Warm with user groups, wget, Lesti FPC

查看:73
本文介绍了带有用户组,wget,Lesti FPC的Magento FPC Cache Warm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Magento网站上使用Lesti FPC,该网站有10个客户组和许多类别/产品.

I'm using Lesti FPC on a Magento site with 10 customer groups and a lot of categories/products.

我创建了一个shell脚本,该脚本会通宵读取sitemap.xml和wget的每个URL,以构建站点的缓存.这对来宾来说非常有用,但是当客户组用户登录时,他们自己在构建缓存(如果这是第一天的话).

I've created a shell script which reads the sitemap.xml and wget's each url overnight to build the cache of the site. 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).

有人知道如何制作一个可以模拟自己登录然后拖曳站点的shell脚本吗? Shell脚本甚至有可能保留自己的会话/cookie信息以保持登录状态吗?如果没有,还有其他想法吗?

Does anyone know how to make a shell script that could simulate logging itself in and then trawl the site? Is it even possible for a shell script to hold its own session/cookie information to remain logged in? and if not, any other ideas?

非常感谢

推荐答案

因此,由于进行了一些Google搜索和多次试错,我找到了一个我认为应该分享的解决方案.

So thanks to some Googling and lots of trial and error, I've found a solution which I thought I'd share.

可以使用WGET通过保存和加载cookie来保存会话/cookie信息. Magento有其自身的局限性,因为您需要在登录之前建立会话cookie,否则脚本将被重定向到"enable-cookies"页面而不是登录,因此脚本如下;

You can use WGET to hold session/cookie information by saving and loading the cookies. 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;

#!/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

这是基础,因此现在非常容易地从sitemap.xml加载所有URL并构建缓存的已登录版本.

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.

向Grafista提供建议,以帮助他们保存Cookie信息.

Props to Grafista for a steer on saving cookie info.

缓存愉快!

编辑-根据要求显示原始代码

EDIT - AS PER REQUEST TO SHOW THE ORIGINAL CODE

以下是循环浏览站点地图并加载每个页面以为访客建立缓存的代码.将其另存为cachewarm.sh并创建一个cronjob使其每晚运行(不要忘记先删除或使页面缓存过期)

Here's the code to cycle through the sitemap and load each page to build the cache for guests. Save this as cachewarm.sh and create a cronjob to run it each night (dont forget to delete or expire your pagecache first)

#!/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 -

这篇关于带有用户组,wget,Lesti FPC的Magento FPC Cache Warm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆