Skip to content

Instantly share code, notes, and snippets.


Erik Hansen erikhansen

View GitHub Profile
erikhansen /
Created Aug 4, 2020 — forked from davidalger/
Script to crawl and warm the cache two levels deep on Magento demo Pods via CronJob spec
set -euo pipefail
echo "==> [$(date +%H:%M:%S)] waiting on readiness"
while : ; do
RESPONSE_CODE=$(curl -sI "${FRONT_URL}" 2>/dev/null | head -n1 | awk '{print $2}')
erikhansen /
Last active Jul 15, 2020
Issue with using flock with Magento's cron


This applies to Magento 2.3+.

If you have your crontab configured to run the bin/magento cron:run command using flock, you should either:

  • Remove flock, since it's technically not necessary as of Magento 2.3.2
  • Pass the -o command to flock, as this will prevent the indefinitely running bin/magento queue:consumers:start processes spawned by bin/magento cron:run from holding a lock when they shouldn't be.


erikhansen /
Last active Jun 13, 2022
Running Warden on Windows with WSL 1 & 2

Running Warden on Windows with WSL 2

See this Github comment thread for any issues or additional context for getting Warden running on Windows with WSL 2.

The instructions below cover how to install Warden on Windows, using WSL 2.

  1. Install Ubuntu 20 LTS in WSL 2
    1. To access the shell/terminal inside of Ubuntu WSL, open the Ubuntu 20.04 program that will have been installed in the step above (If you want to be able to copy/paste, see here. Going forward, this article assumes you will run all commands inside of the Ubuntu terminal
  2. Install Docker Desktop (these instructions were tested using Docker 4.9.0 on June 13th, 2022)
  3. Install homebrew `
View varnish administration.txt
# 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 "" or BereqHeader:X-User-IP eq ""'
# Monitor PURGE requests hitting Varnish
View GH-19597-fix-setup-db-status-inaccuracy.patch
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
+ //Ugly patch (MariaDB compatibility)
+ $firstParams = $first->getDiffSensitiveParams();
erikhansen /
Last active Feb 4, 2021
Magento 2 performance comparison after disabling unnecessary third-party extensions


I ran some tests to determine the speed impact of removing unnecessary third-party extensions, per this article: 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 /
Created Dec 19, 2019
Default M2 Production Settings
erikhansen /
Last active Jul 19, 2021
Patch Magento 2 extension that must be installed in app/code

See also this alternative approach:

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 / flush_apcu_cache.rake
Created Dec 13, 2019
Rake file to cache apcu cache upon each deployment. Used in conjunction with
View flush_apcu_cache.rake
# 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'
erikhansen /
Last active Dec 12, 2019
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: