Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Cache #2

Merged
merged 18 commits into from Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -28,4 +28,5 @@ web/wp
.idea/

# WP Plugins
web/app/sunrise.php
web/app/object-cache.php
web/app/advanced-cache.php
3 changes: 3 additions & 0 deletions .slugignore
Expand Up @@ -10,3 +10,6 @@ phpcs.xml

# Heroku Deploy Configuration
app.json

# drop in plugins
vendor/dumpster
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -156,6 +156,17 @@ After installing WordPress you need to enable the two Amazon Plugins in the Cont

--------

###### Cache (Optional)
Redis caching can improve your application performance by x20 or even more.
It saves the results of sql queries in ram memory, therefore reducing loading times.

You only need to attach the Heroku Redis addon to your application.
```bash
$ heroku addons:create heroku-redis:hobby-dev
```

--------

###### Deploy / Update
Now you can deploy your project to heroku (or when you update your application):
```bash
Expand Down
3 changes: 3 additions & 0 deletions app.json
Expand Up @@ -63,6 +63,9 @@
},
{
"plan": "scheduler:standard"
},
{
"plan": "heroku-redis:hobby-dev"
}
],
"buildpacks": [
Expand Down
20 changes: 18 additions & 2 deletions composer.json
Expand Up @@ -20,6 +20,7 @@
"url": "https://wpackagist.org"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=7.0",
"ext-gettext": "*",
Expand All @@ -34,27 +35,42 @@
"wpackagist-plugin/all-in-one-seo-pack": "2.3.11.3",
"wpackagist-plugin/nginx-helper": "1.9.9",
"wpackagist-plugin/sendgrid-email-delivery-simplified": "1.10.7",
"humanmade/s3-uploads": "2.0.0-beta2"
"frc/batcache": "1.3-a1",
"wpackagist-plugin/redis-cache": "1.3.5",
"predis/predis": "1.1.1",
"humanmade/s3-uploads": "2.0.0-beta2",
"wpackagist-plugin/debug-bar": "0.8.4"
},
"require-dev": {
"heroku/heroku-buildpack-php": "*",
"squizlabs/php_codesniffer": "^2.5.1"
},
"extra": {
"installer-paths": {
"vendor/dumpster/": [
"wpackagist-plugin/redis-cache",
"frc/batcache"
],
"web/app/mu-plugins/{$name}/": [
"wpackagist-plugin/wordfence",
"wpackagist-plugin/nginx-helper",
"wpackagist-plugin/sendgrid-email-delivery-simplified",
"humanmade/s3-uploads"
],
"web/app/plugins/{$name}/": [
"wpackagist-plugin/all-in-one-seo-pack"
"wpackagist-plugin/all-in-one-seo-pack",
"wpackagist-plugin/debug-bar"
],
"web/app/themes/{$name}/": [
"type:wordpress-theme"
]
},
"dropin-paths": {
"web/app": [
"package:wpackagist-plugin/redis-cache:includes/object-cache.php",
"package:frc/batcache:advanced-cache.php"
]
},
"wordpress-install-dir": "web/wp"
},
"scripts": {
Expand Down
119 changes: 118 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 25 additions & 67 deletions config/application.php
Expand Up @@ -15,7 +15,7 @@
* Use Dotenv to set required environment variables and load .env file in root
*/
$dotenv = new Dotenv\Dotenv($root_dir);
if (file_exists($root_dir . '/.env')) {
if (file_exists($root_dir.'/.env')) {
$dotenv->load();
}

Expand All @@ -30,76 +30,34 @@
}

/**
* Configuration - Database: Heroku JawsDb
* Load Plugin Configurations
*/
$env = getenv('JAWSDB_MARIA_URL');
if ($env) {
$url = parse_url($env);
putenv(sprintf('DB_HOST=%s', $url['host']));
if (array_key_exists('port', $url)) {
putenv(sprintf('DB_PORT=%s', $url['port']));
function includeDirectory($dir)
{
foreach (scandir($dir) as $filename) {
$path = $dir . '/' . $filename;
if (is_file($path)) {
require_once($path);
}
}
putenv(sprintf('DB_USER=%s', $url['user']));
putenv(sprintf('DB_PASSWORD=%s', $url['pass']));
putenv(sprintf('DB_NAME=%s', ltrim($url['path'], '/')));
}

/**
* Configuration - Database: Heroku ClearDb
*/
$env = getenv('CLEARDB_DATABASE_URL');
if ($env) {
$url = parse_url($env);
putenv(sprintf('DB_HOST=%s', $url['host']));
putenv(sprintf('DB_PORT=%s', $url['port']));
putenv(sprintf('DB_USER=%s', $url['user']));
putenv(sprintf('DB_PASSWORD=%s', $url['pass']));
putenv(sprintf('DB_NAME=%s', ltrim($url['path'], '/')));
}
includeDirectory($root_dir."/config/plugins");

/**
* Configuration - Database: Custom
*/
$env = getenv('CUSTOM_DB_URL');
if ($env) {
$url = parse_url($env);
putenv(sprintf('DB_HOST=%s', $url['host']));
putenv(sprintf('DB_PORT=%s', $url['port']));
putenv(sprintf('DB_USER=%s', $url['user']));
putenv(sprintf('DB_PASSWORD=%s', $url['pass']));
putenv(sprintf('DB_NAME=%s', ltrim($url['path'], '/')));
}
if (!empty(getenv('CUSTOM_DB_URL'))) {
$env = parse_url(getenv('CUSTOM_DB_URL'));

/**
* Configuration - Plugin: S3 Uploads
* @url: https://github.com/humanmade/S3-Uploads
*/
$env = getenv('AWS_S3_URL');
if ($env) {
$url = parse_url($env);

define('S3_UPLOADS_AUTOENABLE', true);
define('S3_UPLOADS_KEY', $url['user']);
define('S3_UPLOADS_SECRET', $url['pass']);
define('S3_UPLOADS_REGION', str_replace(array('s3-', '.amazonaws.com'), array('', ''), $url['host']));
define('S3_UPLOADS_BUCKET', ltrim($url['path'], '/'));
} else {
define('S3_UPLOADS_AUTOENABLE', false);
}
putenv(sprintf('DB_HOST=%s', $env['host']));
if (array_key_exists('port', $env)) {
putenv(sprintf('DB_PORT=%s', $env['port']));
}
putenv(sprintf('DB_USER=%s', $env['user']));
putenv(sprintf('DB_PASSWORD=%s', $env['pass']));
putenv(sprintf('DB_NAME=%s', ltrim($env['path'], '/')));

/**
* Configuration - Plugin: Sendgrid
* @url: https://wordpress.org/plugins/sendgrid-email-delivery-simplified/
*/
if (getenv('SENDGRID_USERNAME') && getenv('SENDGRID_PASSWORD')) {
// Auth method ('apikey' or 'credentials')
define('SENDGRID_AUTH_METHOD', 'credentials');
define('SENDGRID_USERNAME', getenv('SENDGRID_USERNAME'));
define('SENDGRID_PASSWORD', getenv('SENDGRID_PASSWORD'));
} else if (getenv('SENDGRID_API_KEY')) {
// Auth method ('apikey' or 'credentials')
define('SENDGRID_AUTH_METHOD', 'apikey');
define('SENDGRID_API_KEY', getenv('SENDGRID_API_KEY'));
unset($env);
}

/**
Expand Down Expand Up @@ -141,11 +99,6 @@
define('WP_CONTENT_DIR', $webroot_dir . CONTENT_DIR);
define('WP_CONTENT_URL', WP_HOME . CONTENT_DIR);

/**
* Cache
*/
define('WP_CACHE', env('WP_CACHE'));

/**
* DB settings
*/
Expand Down Expand Up @@ -174,8 +127,13 @@
*/
define('AUTOMATIC_UPDATER_DISABLED', true);
define('DISALLOW_FILE_EDIT', true);
define('DISALLOW_FILE_MODS', true);
define('DISABLE_WP_CRON', env('DISABLE_WP_CRON') ?: false);

// Enforce SSL for Login/Admin
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);

/**
* Multi Site
*
Expand Down