Skip to content

Instantly share code, notes, and snippets.

@IvanChepurnyi
Created September 30, 2016 16:00
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanChepurnyi/776d56770eecd5d3e39bde6ea41f9dca to your computer and use it in GitHub Desktop.
Save IvanChepurnyi/776d56770eecd5d3e39bde6ea41f9dca to your computer and use it in GitHub Desktop.
Optimizes autoloader for the best performance on production system
#!/bin/bash
magentodir=$1
cd $magentodir
read -d '' script << PHP
<?php
\$composer = json_decode(file_get_contents('composer.json'), true);
if (!is_array(\$composer['autoload']['psr-0'][''])) {
\$composer['autoload']['psr-0'][''] = [\$composer['autoload']['psr-0'][''], 'var/generation'];
}
if (!isset(\$composer['autoload']['exclude-from-classmap'])) {
\$composer['autoload']['exclude-from-classmap'] = ['**/dev/**', '**/update/**', '**/Test/**'];
}
file_put_contents('composer.json', json_encode(\$composer, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
PHP
phpscript=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo $script > /tmp/$phpscript
php -f /tmp/$phpscript
rm /tmp/$phpscript
composer config optimize-autoloader true
composer dump-autoload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment