-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
How to modify start.php if using yii2? #47
Comments
Yii2 server.php <?php
require_once __DIR__ . '/vendor/autoload.php';
use Adapterman\Adapterman;
use Workerman\Worker;
use Workerman\Lib\Timer;
Adapterman::init();
require __DIR__.'/start.php';
$http_worker = new Worker('http://0.0.0.0:8080');
$http_worker->count = (int) shell_exec('nproc') * 4;
$http_worker->name = 'AdapterMan-Yii2';
$http_worker->onWorkerStart = static function () {
WorkerTimer::init();
};
$http_worker->onMessage = static function ($connection) {
$_SERVER['SCRIPT_FILENAME'] = '/app/index.php'; // fix
$_SERVER['SCRIPT_NAME'] = '/index.php'; // fix
header(WorkerTimer::$date); // optional, the Date header is added automatically with Nginx or any other web server
$connection->send(
run()
);
};
class WorkerTimer
{
public static $date;
public static function init()
{
self::$date = 'Date: '.gmdate('D, d M Y H:i:s').' GMT';
Timer::add(1, function() {
WorkerTimer::$date = 'Date: '.gmdate('D, d M Y H:i:s').' GMT';
});
}
}
Worker::runAll(); start.php <?php
// uncomment the following block to debug this app
/*
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
error_reporting(E_ALL);
ini_set('display_errors','on');
*/
define('YII_ENABLE_ERROR_HANDLER', false);
require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
// Change to your config
$config = [
'id' => 'benchmark',
'basePath' => __DIR__ . '/app',
'components' => [
// Functions are faster than array declarations,
// since they avoid the cost of Dependency Injection.
'db' => function() {
return new yii\db\Connection([
'dsn' => 'mysql:host=tfb-database;dbname=hello_world',
'username' => 'benchmarkdbuser',
'password' => 'benchmarkdbpass',
'charset' => 'utf8',
'attributes' => [
PDO::ATTR_PERSISTENT => true,
],
'enableLogging' => false,
'enableProfiling' => false,
'enableSchemaCache' => true,
'schemaCache' => 'cache',
'schemaCacheDuration' => 3600,
]);
},
'cache' => function() {
return new yii\caching\FileCache([
'cachePath' => '/tmp/yii2-cache',
'gcProbability' => 0,
]);
},
'urlManager' => function() {
return new yii\web\UrlManager([
'enablePrettyUrl' => true,
]);
},
// These components are overloaded for a small gain in performance (no DI)
'request' => function() { return new yii\web\Request(); },
'response' => function() { return new yii\web\Response(); },
],
];
//(new yii\web\Application($config))->run();
function run()
{
global $config;
ob_start();
(new yii\web\Application($config))->run();
return ob_get_clean();
} You can check it in the benchmark, I used the same code that with php-fpm. Perhaps will be good to add an issue for this line in Yii2 repo.
The code in the benchmark |
Yii2 bechmark results with php-fpm and Adapterman: |
Commit f1f5b3c, fix the |
How to modify it?
Thanks.
The text was updated successfully, but these errors were encountered: