redis 的方案
/**
* 测试并发操作
* @author zhsngq
* @date 2019-11-01
* @return
*/
public function actionTest()
{
$tr = Yii::$app->db->beginTransaction();
try {
$sql = "INSERT INTO `hudong`.`test` (`sum`) VALUES (1) ; ";
\Yii::$app->db->createCommand($sql)->execute();
$count = Yii::$app->redis->get($this->key);
if (($count -1) < 0) {
throw new \Exception("Error Processing Request", 1);
}
Yii::$app->redis->set($this->key,$count-1);
// if (Yii::$app->redis->decr($this->key) < 0) {
// throw new \Exception("error", 1);
// }
$tr->commit();
} catch (\Exception $e) {
$tr->rollBack();
throw new \Exception($e->getMessage(), 1);
}
echo "ok";
}
/**
* 初始化redis数据
* @author zhsngq
* @date 2019-11-01
* @return [type]
*/
public function actionInit()
{
echo Yii::$app->redis->set($this->key, 100);
}
mysql
- 查找当前睡眠的链接 show processlist;
SHOW GLOBAL VARIABLES LIKE 'wait_timeout';
SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';
set global wait_timeout=30;
SET GLOBAL interactive_timeout=30;
- mysql status : show status like 'threads_%';
php-fpm 加入慢log
; Note: slowlog is mandatory if request_slowlog_timeout is set
2 slowlog = /work/slow.log.slow
1
325 ; The timeout for serving a single request after which a PHP backtrace will be
1 ; dumped to the 'slowlog' file. A value of '0s' means 'off'.
2 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
3 ; Default Value: 0
4 request_slowlog_timeout = 1s
5
6 ; Depth of slow log stack trace.
7 ; Default Value: 20
8 ;request_slowlog_trace_depth = 20