Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
# clear the entire cache
varnishadm "ban req.url ~ /"
# monitor varnish log with multiple patterns
varnishlog | grep 'eqURL\|Age:\|VCL_call\|TTL\|Expires:\|Cache-Control:'
# Use a query with varnishlog to watch requests from a specific IP
varnishlog -q 'ReqHeader:X-User-IP eq "1.2.3.4" or BereqHeader:X-User-IP eq "1.2.3.4"'
# Monitor PURGE requests hitting Varnish
diff --git a/Declaration/Schema/Comparator.php b/Declaration/Schema/Comparator.php
--- a/Setup/Declaration/Schema/Comparator.php
+++ b/Setup/Declaration/Schema/Comparator.php
@@ -24,7 +24,38 @@
*/
public function compare(ElementInterface $first, ElementInterface $second)
{
+ // Code below pulled from https://github.com/magento/magento2/issues/19597#issuecomment-463611130
+ //Ugly patch (MariaDB compatibility)
+ $firstParams = $first->getDiffSensitiveParams();
@erikhansen
erikhansen / README.md
Last active February 4, 2021 16:05
Magento 2 performance comparison after disabling unnecessary third-party extensions

Overview

I ran some tests to determine the speed impact of removing unnecessary third-party extensions, per this article: https://www.integer-net.com/make-magento-2-small-again/ The TL;DR is that pages loaded about 10% faster (with full_page and block_html disabled) with the unnecessary extensions removed.

Extensions I removed:

"replace": {
        "magento/module-dhl": "*",
        "magento/module-fedex": "*",
@erikhansen
erikhansen / settings.sh
Created December 19, 2019 22:14
Default M2 Production Settings
#!/bin/bash
TODO
@erikhansen
erikhansen / README.md
Last active February 28, 2023 13:59
Patch Magento 2 extension that must be installed in app/code

See also this alternative approach: https://gist.github.com/cmtickle/8900629447429126ffd7ff84e56ec780#to-patch-code-in-appcode

If you need to patch an M2 extension that isn't available to be installed via Composer, and you're concerned about losing edits directly to files in app/code/<Vendor> directory, you can install and then patch the extension locally using these steps:

  1. Copy the extension into an arbitrary folder location like app/code/packages/VendorName/ModuleName (this assumes this module has a composer.json file with the package name of vendorname/module-modulename)

  2. Run this command to add your custom package location to the composer repositories list:

    composer config repositories.vendorname/module-modulename path app/packages/VendorName/ModuleName
    
  3. Require the extension:

@erikhansen
erikhansen / flush_apcu_cache.rake
Created December 13, 2019 00:04
Rake file to cache apcu cache upon each deployment. Used in conjunction with https://github.com/davidalger/capistrano-magento2#usage
# Clear APCU (unsure if this is necessary, but playing it on the safe side)
after "deploy:published", "cachetool:apcu:clear" do
on release_roles :all do
within release_path do
execute :cachetool, 'apcu:cache:info'
execute :cachetool, 'apcu:cache:clear'
end
end
end
@erikhansen
erikhansen / issue.md
Last active March 26, 2024 14:53
Amasty M2 Full Page Cache Warmer Issue - Submitted this issue to Amasty on 2019-12-11

I have a client using this extension, and we recently discovered a big performance issue.

Description: The query generated by the \Amasty\Fpc\Model\ResourceModel\Activity::matchUrl method runs a query on a table that is missing an index.

Here is a screenshot showing the slow query:

Slow query in New Relic

Once the client added a MySQL index for the table, the slow query went away:

@erikhansen
erikhansen / _README.md
Last active April 29, 2021 08:22
Patch for `INSERT INTO search_tmp_` search issue: https://github.com/magento/magento2/issues/15545
@erikhansen
erikhansen / _readme.md
Last active March 21, 2025 21:42
Crawl Magento 1 / Magento 2 site for pricing

Overview

This basic script crawls a Magento 1 or Magento 2 website and logs the prices, SKUs, and product urls to a CSV file. This script was put togther for a company that had consent from the website(s) being scraped. Please use responsibility.

This script uses https://scrapy.org/

This script was tested on macOS Mojave, but it should run on any *NIX system.

You can tweak the body.css code to match the specific CSS selectors on the site you're crawling. See this documentation. When you're testing this script, refer to the command above the def parse_item line to learn how to run the code for only a single product.

@erikhansen
erikhansen / README.md
Last active October 17, 2019 22:55
Kraken Ink Template Readme

Kraken ExtensionName Extension

Description

Give a brief description of the extension here.

Usage Instructions

  • List any usage and deployment instructions
  • Consider including any preference overrides that may conflict with other extension