-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace multidialogo\RawMailerSdk; | ||
|
||
class ForksCounter | ||
{ | ||
public static function getApproximativelyAailable(): int | ||
{ | ||
// Get max number of user processes from ulimit | ||
$ulimitProcesses = (int)trim(shell_exec('ulimit -u')); | ||
echo "Max user processes (ulimit -u): $ulimitProcesses\n"; | ||
|
||
// Get max number of open file descriptors | ||
$ulimitFiles = (int)trim(shell_exec('ulimit -n')); | ||
echo "Max open files (ulimit -n): $ulimitFiles\n"; | ||
|
||
// Get max PID limit from proc file system (Linux-specific) | ||
$pidMax = (int)trim(file_get_contents('/proc/sys/kernel/pid_max')); | ||
echo "Max PID value (pid_max): $pidMax\n"; | ||
|
||
// Memory available on the system (Linux-specific) | ||
$memInfo = file_get_contents('/proc/meminfo'); | ||
preg_match('/MemAvailable:\s+(\d+) kB/', $memInfo, $matches); | ||
$availableMemoryKB = isset($matches[1]) ? (int)$matches[1] : 0; | ||
echo "Available memory (kB): $availableMemoryKB kB\n"; | ||
|
||
// Total number of available forks depends on the lesser of the ulimit, pid_max, and available system memory. | ||
// This is a rough estimate since each forked process requires memory and resources. | ||
// FIXME: save this to file based on average memory peak | ||
$estimatedForksByMemory = $availableMemoryKB / 20000; // Assume each process uses about 20MB (adjust as necessary) | ||
|
||
return min($ulimitProcesses, $pidMax, $estimatedForksByMemory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace multidialogo\RawMailerSdk; | ||
|
||
|
||
use InvalidArgumentException; | ||
|
||
class MessageSizeException extends InvalidArgumentException | ||
{ | ||
private int $messageSize; | ||
|
||
private int $maxSize; | ||
|
||
private string $driver; | ||
|
||
private ?string $suggestedDriver; | ||
|
||
public function __construct(int $messageSize, int $maxSize, string $driver, ?string $suggestedDriver) | ||
{ | ||
parent::__construct("Message size {$messageSize}, not allowed for driver: {$driver}. Suggested driver: {$suggestedDriver}"); | ||
|
||
$this->messageSize = $messageSize; | ||
$this->maxSize = $maxSize; | ||
$this->driver = $driver; | ||
$this->suggestedDriver = $suggestedDriver; | ||
} | ||
|
||
public function getMessageSize(): int | ||
{ | ||
return $this->messageSize; | ||
} | ||
|
||
public function getMaxSize(): int | ||
{ | ||
return $this->maxSize; | ||
} | ||
|
||
public function getDriver(): string | ||
{ | ||
return $this->driver; | ||
} | ||
|
||
public function getSuggestedDriver(): ?string | ||
{ | ||
return $this->suggestedDriver; | ||
} | ||
} |