Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Hansen erikhansen

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

Overview

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.

Before:

@erikhansen
erikhansen / README.md
Last active Jun 13, 2022
Running Warden on Windows with WSL 1 & 2
View README.md

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 "1.2.3.4" or BereqHeader:X-User-IP eq "1.2.3.4"'
# 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 https://github.com/magento/magento2/issues/19597#issuecomment-463611130
+ //Ugly patch (MariaDB compatibility)
+ $firstParams = $first->getDiffSensitiveParams();
@erikhansen
erikhansen / README.md
Last active Feb 4, 2021
Magento 2 performance comparison after disabling unnecessary third-party extensions
View README.md

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 Dec 19, 2019
Default M2 Production Settings
View settings.sh
#!/bin/bash
TODO
@erikhansen
erikhansen / README.md
Last active Jul 19, 2021
Patch Magento 2 extension that must be installed in app/code
View README.md

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 Dec 13, 2019
Rake file to cache apcu cache upon each deployment. Used in conjunction with https://github.com/davidalger/capistrano-magento2#usage
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'
end
end
end
@erikhansen
erikhansen / issue.md
Last active Dec 12, 2019
Amasty M2 Full Page Cache Warmer Issue - Submitted this issue to Amasty on 2019-12-11
View issue.md

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: