|
30 | 30 | use Froxlor\FileDir; |
31 | 31 | use Froxlor\PhpHelper; |
32 | 32 | use Froxlor\Settings; |
| 33 | +use InvalidArgumentException; |
33 | 34 |
|
34 | 35 | class Fpm |
35 | 36 | { |
@@ -201,6 +202,7 @@ public function createConfig($phpconfig) |
201 | 202 |
|
202 | 203 | // possible slowlog configs |
203 | 204 | if ($phpconfig['fpm_slowlog'] == '1') { |
| 205 | + $this->durationCompare($phpconfig['fpm_reqterm'], $phpconfig['fpm_reqslow']); |
204 | 206 | $fpm_config .= 'request_slowlog_timeout = ' . $phpconfig['fpm_reqslow'] . "\n"; |
205 | 207 | $slowlog = FileDir::makeCorrectFile(Settings::Get('system.logfiles_directory') . '/' . $this->domain['loginname'] . '-php-slow.log'); |
206 | 208 | $fpm_config .= 'slowlog = ' . $slowlog . "\n"; |
@@ -239,8 +241,8 @@ public function createConfig($phpconfig) |
239 | 241 |
|
240 | 242 | if ($this->domain['openbasedir_path'] == '0' && strstr($this->domain['documentroot'], ":") === false) { |
241 | 243 | $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); |
244 | 246 | } else { |
245 | 247 | $openbasedir = Domain::appendOpenBasedirPath($this->domain['customerroot'], true); |
246 | 248 | } |
@@ -439,4 +441,40 @@ public function getAliasConfigDir($createifnotexists = true) |
439 | 441 |
|
440 | 442 | return $configdir; |
441 | 443 | } |
| 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 | + } |
442 | 480 | } |
0 commit comments