mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
redis use pconnect when php runs in fpm mode
This commit is contained in:
@@ -40,7 +40,20 @@ class class_cache_redis {
|
|||||||
if (isset($config['timeout']) && is_numeric($config['timeout'])) {
|
if (isset($config['timeout']) && is_numeric($config['timeout'])) {
|
||||||
$params[] = $config['timeout'];
|
$params[] = $config['timeout'];
|
||||||
}
|
}
|
||||||
$connectResult = $redis->connect(...$params);
|
if ($this->isFpmMode()) {
|
||||||
|
try {
|
||||||
|
$connectResult = $redis->pconnect(...$params);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
do_log("redis pconnect failed: {$e->getMessage()}, retry one time", 'error');
|
||||||
|
$redis->close();
|
||||||
|
$redis = new Redis();
|
||||||
|
$connectResult = $redis->pconnect(...$params);
|
||||||
|
}
|
||||||
|
do_log("redis pconnect: $connectResult", 'debug');
|
||||||
|
} else {
|
||||||
|
$connectResult = $redis->connect(...$params);
|
||||||
|
do_log("redis connect: $connectResult", 'debug');
|
||||||
|
}
|
||||||
if (!empty($config['password'])) {
|
if (!empty($config['password'])) {
|
||||||
$connectResult = $connectResult && $redis->auth($config['password']);
|
$connectResult = $connectResult && $redis->auth($config['password']);
|
||||||
}
|
}
|
||||||
@@ -55,6 +68,11 @@ class class_cache_redis {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isFpmMode(): bool
|
||||||
|
{
|
||||||
|
return php_sapi_name() === 'fpm-fcgi';
|
||||||
|
}
|
||||||
|
|
||||||
function getIsEnabled() {
|
function getIsEnabled() {
|
||||||
return $this->isEnabled;
|
return $this->isEnabled;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user