mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +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'])) {
|
||||
$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'])) {
|
||||
$connectResult = $connectResult && $redis->auth($config['password']);
|
||||
}
|
||||
@@ -55,6 +68,11 @@ class class_cache_redis {
|
||||
return true;
|
||||
}
|
||||
|
||||
private function isFpmMode(): bool
|
||||
{
|
||||
return php_sapi_name() === 'fpm-fcgi';
|
||||
}
|
||||
|
||||
function getIsEnabled() {
|
||||
return $this->isEnabled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user