Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@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 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 / warmer-cron.sh
Created August 4, 2020 16:54 — forked from davidalger/warmer-cron.sh
Script to crawl and warm the cache two levels deep on Magento demo Pods via CronJob spec
#!/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 July 15, 2020 20:14
Issue with using flock with Magento's cron

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:

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();
# 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
@erikhansen
erikhansen / command.sh
Created May 22, 2018 00:39
File count, grouped by hour modified
find . -printf '%TY-%Tm-%Td %TH\n' | sort | uniq -c
@erikhansen
erikhansen / commands
Last active April 2, 2020 09:14
Magento 2 Local Site Configurations
# Set admin login to 6 days
bin/magento -q config:set admin/security/session_lifetime 518400
# Allow admin logins to be bookmarked
bin/magento -q config:set admin/security/use_form_key 0
# Set customer login to 4 hours
bin/magento -q config:set web/cookie/cookie_lifetime 14400
# Misc dev settings
bin/magento -q config:set dev/css/merge_css_files 0
bin/magento -q config:set dev/js/merge_files 0
bin/magento -q config:set dev/js/enable_js_bundling 0
@erikhansen
erikhansen / robots.txt
Last active April 2, 2020 09:11
Recommended Magento 2 robots.txt
# TODO: Update this with appropriate url
Sitemap: https://www.example.com/sitemap.xml
User-agent: *
# Paths (clean URLs)
Disallow: /index.php/
Disallow: /catalog/product_compare/
# Need to allow these urls paths to be indexed, since M2 commonly includes these links in sitemap.xml
# Disallow: /catalog/category/view/
@erikhansen
erikhansen / settings.sh
Created December 19, 2019 22:14
Default M2 Production Settings
#!/bin/bash
TODO