https://join.slack.com/t/yii/shared_invite/MjIxMjMxMTk5MTU1LTE1MDE3MDAwMzMtM2VkMTMyMjY1Ng
11111111138,024d7994-a26c-4c20-9894-13934840fc31
working using that, but I guess I can live without the dashes
Server suddenly returns error code 500
It is found that the IO speed of the hard disk of the php-fpm process is 130Mb/s , and the corresponding file is /runtime/logs/app.log
Q | A |
---|---|
Yii version | 2.0.22 |
PHP version | 7.1 |
Operating system | linux |
main.php
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['info','error', 'warning'],
'logVars' => ['_GET','_POST'],//记录全局变量的参数,$_GET,$_SERVER...,默认会增加一条info记录
'logFile' => '@app/runtime/logs/-app.log',
'maxFileSize' => 1024 * 2000, // 2G
'maxLogFiles' => 1,
]
],
],
When I read the source code in vendor/yiisoft/yii2/log/FileTarget.php
, I found that I should set rotateByCopy = false
.
file:vendor/yiisoft/yii2/log/FileTarget.php
/**
* @var bool Whether to rotate log files by copy and truncate in contrast to rotation by
* renaming files. Defaults to `true` to be more compatible with log tailers and is windows
* systems which do not play well with rename on open files. Rotation by renaming however is
* a bit faster.
*
* The problem with windows systems where the [rename()](https://secure.php.net/manual/en/function.rename.php)
* function does not work with files that are opened by some process is described in a
* [comment by Martin Pelletier](https://secure.php.net/manual/en/function.rename.php#102274) in
* the PHP documentation. By setting rotateByCopy to `true` you can work
* around this problem.
*/
public $rotateByCopy = true;
But I don't think this configuration will cause the server to stop serving.Then I found a bit of confusion.
file:vendor/yiisoft/yii2/log/FileTarget.php
public function export()
{
$logPath = dirname($this->logFile);
FileHelper::createDirectory($logPath, $this->dirMode, true);
$text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n";
if (($fp = @fopen($this->logFile, 'a')) === false) {
throw new InvalidConfigException("Unable to append to log file: {$this->logFile}");
}
@flock($fp, LOCK_EX); ########### lock file
if ($this->enableRotation) {
clearstatcache();
}
if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) {
@flock($fp, LOCK_UN); ########### unlock file
@fclose($fp);
$this->rotateFiles(); ########### when rotateByCopy = true , copying file content to aother file is slow (2GB size). Causes multiple php-fpm processes copy files at the same time
########### Why unlock file before rotateFiles() @see:https://github.com/yiisoft/yii2/pull/3563#issuecomment-425630598
########### Maybe we need a separate lock file for rotateFiles().
// ...
} else {
// ...
}
// ...
}
Is my idea right?
public function init() {
parent::init();
$this->view->registerJs(/* JS Code */, View::POS_READY, 'modalform');
}
<?php \yii\widgets\Pjax::begin([ 'id' => 'pgrid' ]); ?>
<?= ModalForm::widget([
//THIS IS THE WIDGET WITH DUPLICATED JS
]); ?>
<?php $form = ActiveForm::begin(['method' => 'POST', 'options' => ['data-pjax' => true, 'class' => 'bmd-form-group bmd-form-group-sm']]); ?>
<!-- ['inputOptions' => ['autofocus' => 'autofocus'] ] -->
<?= $form->field($searchModel, 'query')->textInput( ['id' => 'inputField', 'placeholder' => 'Search records'])->label(false); ?>
<?= Html::submitButton('<i class="material-icons">search</i>', [ 'class' => 'btn btn-rose btn-round btn-just-icon' ]); ?>
<?php ActiveForm::end(); ?>
<script>
$('#inputField').on('change', function(ev) {
$(this).parents('form').submit();
ev.preventDefault();
});
</script>
<?= GridView::widget([]); ?>
if (! Yii::$app->request->isPjax)
$this->view->registerJs(/* stuff */);
http://iqv2.com:81/claim/update?id=3
yii\base\Controller
versus yii\web\Controller
What is the best practice for using Access Tokens in apis?
$identity = self::find()->where(['access_token' => $token])->select('id')->one();
if ($identity == null) return null;
//As per the recommendations, https://www.yiiframework.com/doc/api/2.0/yii-web-identityinterface#findIdentityByAccessToken()-detail
// null should be re turned here.
if (!Yii::$app->authManager->checkAccess($identity->id, Permissions::IdentifyWithAccessToken))
return null;
return $identity;
this doesn't seem all that secure having it in plain text.
$model->link('organisationUsers', Yii::$app->user->identity, ['status' => 10, 'role' => 10]);
.in /app/vendor/yiisoft/yii2/db/BaseActiveRecord.php at line 1350– yii\db\BaseActiveRecord::bindModels(['organisation_id' => 'id'], common\models\User, common\models\Organisation)
.I have tried
'container' => [
'definitions' => [
yii\base\Model::class => app\models\Model::class,
but that doesn't do anything. The models dont have any of the app\models\Model::class
and are not instances of it
$model = TestModel::findOne(['id' => 3]);
$success = $model instanceof \app\models\Model;
if (!$success) Yii::$app->session->addFlash('danger', 'failed to override');
this always fails
Hey guys, I have a question regarding the yiisoft/yii2-queue and the monitor extension from Roman Zhuravlev. I need to implement a worker affinity for jobs.
I start worker using supervisor in docker container (1 or many):
[group:worker]
programs=yii-queue-worker
priority=40
[program:yii-queue-worker]
command=yii queue/listen --verbose=1 --php-binary=/usr/local/bin/php --isolate=1 --color=0 --interactive=0
process_name=%(program_name)s_%(process_num)02d
autostart=true
numprocs=5
autorestart=true
startsecs=14
startretries=20
user=application
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
So I have 5 isolated queue listeners up and running in each container / host.
Now a job A was pushed for the first time and gets executed by worker A on host A.
Then I remember (using a simple key value store in redis) that job A was processed by worker A on host A.
Works fine so far and I can access that information everywhere.
Now the next time job A comes I need to ensure that this job A will only gets executed on worker A on host A.
Until worker A on host A is busy that job A needs to wait.
I tried a lot to get that done but job A gets always executed by one of the next free available worker process.
I use own extended classes doing nothing atm then calling the parent class methods to be able to customize.
Here`s my config:
'queue' => [
'class' => ProjectQueue::class,
'commandClass' => ProjectCommand::class,
'as log' => [
'class' => ProjectLogBehavior::class,
'autoFlush' => true,
],
'as jobMonitor' => [
'class' => ProjectJobMonitor::class,
],
'as workerMonitor' => [
'class' => ProjectWorkerMonitor::class,
],
'mutex' => [
'class' => MysqlMutex::class,
'db' => 'db',
'autoRelease' => false,
],
'mutexTimeout' => 10,
'db' => 'db',
'channel' => 'master-queue',
'deleteReleased' => true,
'ttr' => 200,
'attempts' => 1,
],
Now my question. Is that possible at all? And where I need to slide in to get that done.
Thanks in advance !
🎁 Yii news 2020, issue 8: https://opencollective.com/yiisoft/updates/yii-news-2020-issue-8
🎄 Happy New Year!