Skip to content

Commit 85bbf61

Browse files
committed
WEB: Don't make the cache database depend on the hostname
This avoids having two caches when accessing the website with or without a www and this is also more robust. Make use of the DEV_SERVER constant and allow to enable it by setting an environment variable.
1 parent dcbbef2 commit 85bbf61

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/Models/BasicModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct()
1717
if (is_null(self::$cache)) {
1818
try {
1919
$driver = extension_loaded('redis') ? 'redis' : 'predis';
20-
$database = $_SERVER['HTTP_HOST'] === 'www.scummvm.org' ? 8 : 7;
20+
$database = DEV_SERVER ? 7 : 8;
2121
$config = extension_loaded('redis')
2222
? new RedisConfig(['database' => $database])
2323
: new PredisConfig(['database' => $database]);

public_html/index.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55
* Development only
66
* Don't re-route static file requests to index.php
77
* And change directory context to public_html
8+
*
9+
* When DEV_SERVER is true a different Redis database is chosen
10+
* It's true when running using PHP built-in server or
11+
* if the DEV_SERVER environment variable is set to 1
812
*/
913
if (isset($_SERVER['SERVER_SOFTWARE']) &&
10-
\preg_match("/PHP [\d\.]+ Development Server/",$_SERVER['SERVER_SOFTWARE'])) {
11-
chdir('public_html');
14+
\preg_match("/PHP [\d\.]+ Development Server/",$_SERVER['SERVER_SOFTWARE'])) {
1215
define('DEV_SERVER', true);
16+
chdir('public_html');
1317
if (\preg_match('/\.(?:png|jpg|jpeg|gif|css|js|svg)/', $_SERVER["REQUEST_URI"])) {
1418
return false;
1519
}
20+
} else if (getenv('DEV_SERVER') === "1") {
21+
define('DEV_SERVER', true);
22+
} else {
23+
define('DEV_SERVER', false);
1624
}
1725

1826
require_once __DIR__ . '/../vendor/autoload.php';

0 commit comments

Comments
 (0)