|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -// comment out the following two lines when deployed to production |
4 |
| -//defined('YII_DEBUG') or define('YII_DEBUG', false); |
5 |
| -//defined('YII_ENV') or define('YII_ENV', 'prod'); |
6 |
| -//error_reporting(E_ALL); |
7 |
| -//ini_set('display_errors','on'); |
| 3 | +// uncomment the following block to debug this app |
| 4 | +/* |
| 5 | +defined('YII_DEBUG') or define('YII_DEBUG', true); |
| 6 | +defined('YII_ENV') or define('YII_ENV', 'dev'); |
| 7 | +error_reporting(E_ALL); |
| 8 | +ini_set('display_errors','on'); |
| 9 | + */ |
8 | 10 |
|
9 |
| -require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); |
| 11 | +define('YII_ENABLE_ERROR_HANDLER', false); |
| 12 | + |
| 13 | +require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; |
10 | 14 |
|
11 | 15 | $config = [
|
12 |
| - 'id' => 'basic', |
| 16 | + 'id' => 'benchmark', |
13 | 17 | 'basePath' => __DIR__,
|
14 | 18 | 'components' => [
|
15 |
| - 'db' => [ |
16 |
| - 'class' => 'yii\db\Connection', |
17 |
| - 'dsn' => 'mysql:host=tfb-database;dbname=hello_world', |
18 |
| - 'username' => 'benchmarkdbuser', |
19 |
| - 'password' => 'benchmarkdbpass', |
20 |
| - 'charset' => 'utf8', |
21 |
| - 'attributes' => [ |
22 |
| - PDO::ATTR_PERSISTENT => true, |
23 |
| - ], |
24 |
| - 'enableLogging' => false, |
25 |
| - 'enableProfiling' => false, |
26 |
| - 'enableSchemaCache' => true, |
27 |
| - 'schemaCache' => 'cache', |
28 |
| - 'schemaCacheDuration' => 3600, |
29 |
| - ], |
30 |
| - 'cache' => [ |
31 |
| - 'class' => 'yii\caching\FileCache', |
32 |
| - 'cachePath' => '/tmp/yii2-cache', |
33 |
| - ], |
34 |
| - 'urlManager' => [ |
35 |
| - 'enablePrettyUrl' => true, |
36 |
| - ], |
| 19 | + // Functions are faster than array declarations, |
| 20 | + // since they avoid the cost of Dependency Injection. |
| 21 | + 'db' => function() { |
| 22 | + return new yii\db\Connection([ |
| 23 | + 'dsn' => 'mysql:host=tfb-database;dbname=hello_world', |
| 24 | + 'username' => 'benchmarkdbuser', |
| 25 | + 'password' => 'benchmarkdbpass', |
| 26 | + 'charset' => 'utf8', |
| 27 | + 'attributes' => [ |
| 28 | + PDO::ATTR_PERSISTENT => true, |
| 29 | + ], |
| 30 | + 'enableLogging' => false, |
| 31 | + 'enableProfiling' => false, |
| 32 | + 'enableSchemaCache' => true, |
| 33 | + 'schemaCache' => 'cache', |
| 34 | + 'schemaCacheDuration' => 3600, |
| 35 | + ]); |
| 36 | + }, |
| 37 | + 'cache' => function() { |
| 38 | + return new yii\caching\FileCache([ |
| 39 | + 'cachePath' => '/tmp/yii2-cache', |
| 40 | + 'gcProbability' => 0, |
| 41 | + ]); |
| 42 | + }, |
| 43 | + 'urlManager' => function() { |
| 44 | + return new yii\web\UrlManager([ |
| 45 | + 'enablePrettyUrl' => true, |
| 46 | + ]); |
| 47 | + }, |
| 48 | + // These components are overloaded for a small gain in performance (no DI) |
| 49 | + 'request' => function() { return new yii\web\Request(); }, |
| 50 | + 'response' => function() { return new yii\web\Response(); }, |
37 | 51 | ],
|
38 | 52 | ];
|
39 | 53 |
|
|
0 commit comments