Skip to content

Commit 6e0a117

Browse files
committed
avoid 'request_slowlog_timeout' can't be greater than 'request_terminate_timeout' issues in php-fpm; fixes #1378
Signed-off-by: Michael Kaufmann <[email protected]>
1 parent a5c2dac commit 6e0a117

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

lib/Froxlor/Cron/Http/Php/Fpm.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Froxlor\FileDir;
3131
use Froxlor\PhpHelper;
3232
use Froxlor\Settings;
33+
use InvalidArgumentException;
3334

3435
class Fpm
3536
{
@@ -201,6 +202,7 @@ public function createConfig($phpconfig)
201202

202203
// possible slowlog configs
203204
if ($phpconfig['fpm_slowlog'] == '1') {
205+
$this->durationCompare($phpconfig['fpm_reqterm'], $phpconfig['fpm_reqslow']);
204206
$fpm_config .= 'request_slowlog_timeout = ' . $phpconfig['fpm_reqslow'] . "\n";
205207
$slowlog = FileDir::makeCorrectFile(Settings::Get('system.logfiles_directory') . '/' . $this->domain['loginname'] . '-php-slow.log');
206208
$fpm_config .= 'slowlog = ' . $slowlog . "\n";
@@ -239,8 +241,8 @@ public function createConfig($phpconfig)
239241

240242
if ($this->domain['openbasedir_path'] == '0' && strstr($this->domain['documentroot'], ":") === false) {
241243
$openbasedir = Domain::appendOpenBasedirPath($this->domain['documentroot'], true);
242-
} else if ($this->domain['openbasedir_path'] == '2' && strpos(dirname($this->domain['documentroot']).'/', $this->domain['customerroot']) !== false) {
243-
$openbasedir = Domain::appendOpenBasedirPath(dirname($this->domain['documentroot']).'/', true);
244+
} else if ($this->domain['openbasedir_path'] == '2' && strpos(dirname($this->domain['documentroot']) . '/', $this->domain['customerroot']) !== false) {
245+
$openbasedir = Domain::appendOpenBasedirPath(dirname($this->domain['documentroot']) . '/', true);
244246
} else {
245247
$openbasedir = Domain::appendOpenBasedirPath($this->domain['customerroot'], true);
246248
}
@@ -439,4 +441,40 @@ public function getAliasConfigDir($createifnotexists = true)
439441

440442
return $configdir;
441443
}
444+
445+
/**
446+
* 'request_slowlog_timeout' can't be greater than 'request_terminate_timeout'
447+
*
448+
* @param $request_terminate_timeout
449+
* @param $request_slowlog_timeout
450+
* @return void
451+
*/
452+
private function durationCompare(&$request_terminate_timeout, &$request_slowlog_timeout)
453+
{
454+
$to_seconds = function ($str) {
455+
if (!preg_match('/^([0-9]+)([smhd])?$/', $str, $matches)) {
456+
throw new InvalidArgumentException("Invalid format: $str");
457+
}
458+
$value = (int)$matches[1];
459+
$unit = $matches[2] ?? 's';
460+
461+
switch ($unit) {
462+
case 'm':
463+
return $value * 60;
464+
case 'h':
465+
return $value * 3600;
466+
case 'd':
467+
return $value * 86400;
468+
default:
469+
return $value;
470+
}
471+
};
472+
473+
$aSec = $to_seconds($request_terminate_timeout);
474+
$bSec = $to_seconds($request_slowlog_timeout);
475+
476+
if ($bSec > $aSec) {
477+
$request_slowlog_timeout = $request_terminate_timeout;
478+
}
479+
}
442480
}

0 commit comments

Comments
 (0)