{"id":9966,"date":"2018-08-28T06:00:18","date_gmt":"2018-08-28T10:00:18","guid":{"rendered":"https:\/\/blog.litespeedtech.com\/?p=9966"},"modified":"2018-08-28T06:00:18","modified_gmt":"2018-08-28T10:00:18","slug":"cache-crawler-for-prestashop-and-magento-2","status":"publish","type":"post","link":"https:\/\/lswp.store\/index.php\/2018\/08\/28\/cache-crawler-for-prestashop-and-magento-2\/","title":{"rendered":"Crawling Your PrestaShop or Magento 2 Store"},"content":{"rendered":"<p><a href=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null.jpeg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-large wp-image-9968\" src=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-1024x512.jpeg\" alt=\"Cache Crawler for PrestaShop and Magento 2\" width=\"1024\" height=\"512\" srcset=\"https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-1024x512.jpeg 1024w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-300x150.jpeg 300w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-768x384.jpeg 768w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-1536x768.jpeg 1536w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-2048x1024.jpeg 2048w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-1320x660.jpeg 1320w, https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null-600x300.jpeg 600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>We recently released two new crawler scripts: one for Magento 2 stores using <a href=\"https:\/\/www.litespeedtech.com\/products\/cache-plugins\/magento-acceleration\">LiteMage<\/a>, and another for PrestaShop stores using <a href=\"https:\/\/www.litespeedtech.com\/support\/wiki\/doku.php\/litespeed_wiki:cache:lscps\">LSCache<\/a>.<\/p>\n<p>The LSCache\/LiteMage crawler, travels its way through your sitemap file, refreshing pages that have expired in the cache. The purpose is to keep the cache as fresh as possible while minimizing visitor exposure to uncached content.<\/p>\n<h2>Why Crawl Your Store?<\/h2>\n<p>Well, first let\u2019s look at how cache plugins store pages without a crawler. A user request kicks off the whole process. The cache is empty until users start sending requests. The first time a visitor requests a page, the request hits the backend. PHP code is invoked to generate the page, the page is served to the user, and then the page is stored in cache for next time.<\/p>\n<p>That\u2019s a fairly time-consuming process for the server.<\/p>\n<p>Now, let\u2019s look at what happens when a crawler builds the cache. When the crawler requests a page, the request hits the backend. PHP code is invoked to generate the page, but because of the special header that lets LSWS know that this is a crawler that initiated the request, the full page doesn\u2019t need to be served. It is simply stored in cache.<\/p>\n<p>Additionally, with the crawler refreshing expired pages at regular intervals, the chances that a user will encounter an uncached page is significantly diminished. This makes for a faster site.<\/p>\n<p>So, now that you\u2019re sold on the idea, let\u2019s look at how it\u2019s done.<\/p>\n<p><strong>Please Note<\/strong>: The concepts behind the PrestaShop cache crawler script and the Magento 2 cache crawler script are the same, and so the instructions are very similar. Where they differ, we\u2019ll put PrestaShop on the left, and Magento 2 on the right.<\/p>\n<h2>Before You Begin<\/h2>\n<p>There are a few things you need to do before you can begin to use the new script.<\/p>\n<ul>\n<li>You must be using <a href=\"https:\/\/www.litespeedtech.com\/support\/wiki\/doku.php\/litespeed_wiki:cache:lscps\">LiteSpeed Cache for PrestaShop<\/a> or <a href=\"https:\/\/www.litespeedtech.com\/support\/wiki\/doku.php\/litespeed_wiki:cache:litemage2:installation\">LiteMage 2 for Magento 2<\/a>. Follow those links to install and enable the relevant extension.<\/li>\n<li>The crawler must be enabled at the server level, or you will see the warning message <code>Server crawler engine not enabled. Please check...<\/code>. If you are using a shared hosting server, please contact your hosting provider, or see <a href=\"https:\/\/www.litespeedtech.com\/support\/wiki\/doku.php\/litespeed_wiki:cache:lscwp:configuration:enabling_the_crawler#enabling_and_limiting_the_wordpress_crawler\">our instructions<\/a>.<\/li>\n<li>Prepare your site&#8217;s XML sitemap using the tool of your choice.<\/li>\n<\/ul>\n<h3>Generate a Sitemap<\/h3>\n<p>If you haven\u2019t yet generated your sitemap, you can use an online sitemap generator such as <a href=\"https:\/\/www.xml-sitemaps.com\/\">XML-Sitemaps.com<\/a>.<\/p>\n<p>After the crawl is finished, click <strong>DOWNLOAD YOUR XML SITEMAP FILE<\/strong> and put it where the crawler script can access it.<\/p>\n<p>If you\u2019d prefer to do it from within your site, both PrestaShop and Magento 2 have modules that can generate XML sitemaps.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"50%\">PrestaShop<\/td>\n<td width=\"50%\">Magento 2<\/td>\n<\/tr>\n<tr>\n<td>The Google Sitemap module is quite popular for Prestashop, and it&#8217;s fast.<\/p>\n<p>For PrestaShop v1.6, the Google Sitemap Module is installed by default.<\/p>\n<p>For v1.7+, it needs to be installed from source:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/PrestaShop\/gsitemap\/archive\/master.zip\">Download<\/a> and rename file to <code>gsitemap.zip<\/code><\/li>\n<li>Navigate to <strong>Modules and Services<\/strong><\/li>\n<li>Click <strong>Upload a Module<\/strong> and drag the file to into the box to install<\/li>\n<\/ul>\n<p>Configure the sitemap as desired and press <strong>Generate Sitemap<\/strong>. You can find the URL of your new sitemap displayed in the <strong>Your Sitemaps<\/strong> section.<\/td>\n<td>Magento 2 has a builtin module for generating a sitemap and it&#8217;s fast.<\/p>\n<ul>\n<li>Navigate to <strong>Magento Admin &gt; Stores &gt; Settings &gt; Configuration &gt; Catalog &gt; XML Sitemap<\/strong><\/li>\n<li>Set <strong>Generation Settings &gt; Enabled<\/strong> to <code>Yes<\/code><\/li>\n<li>Navigate to<strong> Magento Admin &gt; Marketing &gt; Seo &amp; Search &gt; Sitemap<\/strong><\/li>\n<li>Click the <strong>Add Sitemap<\/strong> button.<\/li>\n<li>Set <strong>Filename<\/strong> = <code>sitemap.xml<\/code> and <strong>Path<\/strong> = <code>\/<\/code><\/li>\n<li>Click the <strong>Save &amp; Generate<\/strong> button<\/li>\n<\/ul>\n<p>A <code>sitemap.xml<\/code> file will be generated in your Magento 2 document root.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Using the Cache Crawler Script<\/h2>\n<p>Download the crawler script from the appropriate link below, and then change the permissions so that the file is executable, like so:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"50%\">PrestaShop<\/td>\n<td width=\"50%\">Magento 2<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/www.litespeedtech.com\/packages\/prestashop\/cachecrawler.sh\">Download<\/a>, then <code>chmod +x cachecrawler.sh<\/code><\/p>\n<p>Usage: <code>bash cachecrawler.sh https:\/\/www.example.com\/sitemap.xml<\/code><\/td>\n<td><a href=\"https:\/\/www.litespeedtech.com\/packages\/litemage2.0\/M2-crawler.sh\">Download<\/a>, then <code>chmod +x M2-crawler.sh<\/code><\/p>\n<p>Usage: <code>bash M2-crawler.sh https:\/\/www.example.com\/sitemap.xml<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The crawler scripts take some parameters:<\/p>\n<ul>\n<li><code>-h<\/code> to display help<\/li>\n<li><code>-m<\/code> for when Desktop &amp; Mobile have different themes<\/li>\n<li><code>-i NUM<\/code> to change the default interval from 0.1s to NUM.<\/li>\n<\/ul>\n<h3>Changing the Crawl Interval<\/h3>\n<p>How often do you want to re-initiate the crawling process? This depends on how long it takes to crawl your site and your Public Cache TTL. The default TTL is one day (24 hours). Let\u2019s say you want to run the script by cron job every 12 hours.<\/p>\n<p>Add the following to your crontab to run twice a day, once at 3:30am and once at 3:30pm:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"50%\">PrestaShop<\/td>\n<td width=\"50%\">Magento 2<\/td>\n<\/tr>\n<tr>\n<td><code>30 3\/15 * * * path_to_script\/cachecrawler.sh https:\/\/www.example.com\/sitemap.xml -m -i 0.2<\/code><\/td>\n<td><code>30 3\/15 * * * path_to_script\/M2-crawler.sh https:\/\/www.example.com\/sitemap.xml -m -i 0.2<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can use <a href=\"https:\/\/crontab.guru\/\">an online crontab tool<\/a> to help you to verify time settings.<\/p>\n<h3>Verifying the Crawler is Working<\/h3>\n<p>When using <a href=\"https:\/\/developers.google.com\/web\/tools\/chrome-devtools\/\">the browser developer tool<\/a>, load a page where the TTL has expired. On the first view after the crawler runs, you should see:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"50%\">PrestaShop<\/td>\n<td width=\"50%\">Magento 2<\/td>\n<\/tr>\n<tr>\n<td><code>X-LiteSpeed-Cache: hit<\/code><\/td>\n<td><code>X-LiteSpeed-Cache: hit,litemage<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The cache hit indicates that the crawler cached the page for you. If the crawler were not running, you\u2019d have gotten a cache miss.<\/p>\n<p>Any questions about our new crawler scripts? Let us know in the comments!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our new cache crawler script travels its way through your sitemap file, refreshing pages that have expired in the cache. <\/p>\n","protected":false},"author":1,"featured_media":9968,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[25,28],"tags":[81,175,232],"class_list":["post-9966","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-litemage","category-cache","tag-crawler","tag-magento","tag-prestashop"],"jetpack_featured_media_url":"https:\/\/lswp.store\/wp-content\/uploads\/2018\/08\/null.jpeg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/9966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/comments?post=9966"}],"version-history":[{"count":0,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/9966\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media\/9968"}],"wp:attachment":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media?parent=9966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/categories?post=9966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/tags?post=9966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}