Skip to content

Commit

Permalink
updates for Swoole 6.0.0 (since Swoole 6.0.0-rc1)
Browse files Browse the repository at this point in the history
Signed-off-by: Demin Yin <[email protected]>
  • Loading branch information
deminy committed Jan 3, 2025
1 parent b27ff35 commit 77a57f2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/swoole/Swoole/Coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,12 @@ public static function waitPid(int $pid, float $timeout = -1): array|false
* @param int|array<int> $signals An integer or an array of integers representing the signal number(s).
* Before Swoole v6.0.0-rc1, only integer is supported.
* @param float $timeout The timeout value in seconds. Minimum value is 0.001. -1 means no timeout.
* @return bool Returns true on success. Returns false on failure.
* @return int|false Returns the signal number received on success, or false on failure.
* @alias Alias of method \Swoole\Coroutine\System::waitSignal().
* @see \Swoole\Coroutine\System::waitSignal()
* @since 4.5.0
*/
public static function waitSignal(int|array $signals, float $timeout = -1): bool
public static function waitSignal(int|array $signals, float $timeout = -1): int|false
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/swoole/Swoole/Coroutine/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public static function waitPid(int $pid, float $timeout = -1): array|false
* @param int|array<int> $signals An integer or an array of integers representing the signal number(s).
* Before Swoole v6.0.0-rc1, only integer is supported.
* @param float $timeout The timeout value in seconds. Minimum value is 0.001. -1 means no timeout.
* @return bool Returns true on success. Returns false on failure.
* @return int|false Returns the signal number received on success, or false on failure.
* @alias This method has an alias of \Swoole\Coroutine::waitSignal().
* @see \Swoole\Coroutine::waitSignal()
* @since 4.5.0
*/
public static function waitSignal(int|array $signals, float $timeout = -1): bool
public static function waitSignal(int|array $signals, float $timeout = -1): int|false
{
}

Expand Down
42 changes: 42 additions & 0 deletions src/swoole/Swoole/Process/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ class Pool
*/
public int $master_pid = -1;

/**
* Process ID of the current worker process.
*
* This property is set right before the "onWorkerStart" callback function of the pool is called when starting the
* worker process. It remains the same throughout the life cycle of the worker process.
*
* @since 6.0.0
* @readonly
*/
public int $workerPid = -1;

/**
* ID of the current worker process.
*
* This property is set right before the "onWorkerStart" callback function of the pool is called when starting the
* worker process. It remains the same throughout the life cycle of the worker process.
*
* @since 6.0.0
* @readonly
*/
public int $workerId = -1;

/**
* List of the worker processes.
*
Expand All @@ -31,6 +53,26 @@ class Pool
*/
public ?array $workers;

/**
* If current worker process is considered as running or not.
*
* This property is set to TRUE right before the "onWorkerStart" callback function of the pool is called when
* starting the worker process. It will be set to FALSE before the "onWorkerStop", "onWorkerExit", or "onShutdown"
* callback function is called.
*
* @since 6.0.0
* @readonly
*/
public bool $workerRunning = true;

/**
* If current (master or worker) process is considered as running or not.
*
* @since 6.0.0
* @readonly
*/
public bool $running = true;

public function __construct(int $worker_num, int $ipc_type = SWOOLE_IPC_NONE, int $msgqueue_key = 0, bool $enable_coroutine = false)
{
}
Expand Down
30 changes: 4 additions & 26 deletions src/swoole/Swoole/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,14 @@ class Runtime
/**
* To enable/disable runtime hooks in coroutines.
*
* For backward-compatible reason, there are four different ways to call this method:
* #1. Swoole\Runtime::enableCoroutine(); // Enable runtime hooks represented by constant SWOOLE_HOOK_ALL.
* #2. Swoole\Runtime::enableCoroutine($flags); // Enable specified runtime hooks.
* #3. Swoole\Runtime::enableCoroutine(true, $flags); // Enable specified runtime hooks.
* #4. Swoole\Runtime::enableCoroutine(false); // Disable runtime hooks.
* Following statements are of the same (when used to disable runtime hooks):
* Swoole\Runtime::enableCoroutine(0); // #2
* Swoole\Runtime::enableCoroutine(true, 0); // #3
* Swoole\Runtime::enableCoroutine(false); // #4
* Before Swoole v6.0.0, this method accepts different types of parameters to enable or disable runtime hooks.
*
* @param int $flags Enable given runtime hooks, or disable all hooks if 0 is passed.
* @return bool TRUE on success, or FALSE on failure.
* @pseudocode-included This is a built-in method in Swoole. The PHP code included inside this method is for explanation purpose only.
*/
public static function enableCoroutine(bool|int $enable = SWOOLE_HOOK_ALL, int $flags = SWOOLE_HOOK_ALL): bool
public static function enableCoroutine(int $flags = SWOOLE_HOOK_ALL): bool
{
if (PHP_SAPI !== 'cli') {
// An E_ERROR level error will be thrown out here.
return false;
}

if (is_int($enable)) {
$flags = max(0, $enable);
} elseif (is_bool($enable)) {
if ($enable === false) {
// Disable runtime hooks.
$flags = 0;
}
} else {
throw new \ErrorException('... expects parameter 1 to be boolean or integer, ...');
}

return self::setHookFlags($flags);
}

Expand All @@ -60,6 +37,7 @@ public static function getHookFlags(): int
* - setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_FILE ^ SWOOLE_HOOK_STDIO): Enable all runtime hooks except file and stdio hooks.
* - setHookFlags(0): Disable runtime hooks.
*
* @param int $flags Enable given runtime hooks, or disable all hooks if 0 is passed.
* @return bool true on success or false on failure
* @since 4.5.0
*/
Expand Down
15 changes: 13 additions & 2 deletions src/swoole/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* Swoole version information.
*/
define('SWOOLE_VERSION', '6.0.0-RC1');
define('SWOOLE_VERSION', '6.0.0');
define('SWOOLE_VERSION_ID', 60000);
define('SWOOLE_MAJOR_VERSION', 6);
define('SWOOLE_MINOR_VERSION', 0);
Expand Down Expand Up @@ -537,7 +537,18 @@
*/
define('SWOOLE_HOOK_SOCKETS', 16384); // 2^14
define('SWOOLE_HOOK_STDIO', 32768); // 2^15
define('SWOOLE_HOOK_PDO_PGSQL', 65536); // 2^16; @since 5.1.0
/*
* Runtime hook flag SWOOLE_HOOK_PDO_PGSQL makes the PDO_PGSQL driver coroutine-friendly. This flag is available only when Swoole is installed with option "--enable-swoole-pgsql" included.
*
* @since 5.1.0
*/
define('SWOOLE_HOOK_PDO_PGSQL', 65536); // 2^16
/*
* Runtime hook flag SWOOLE_HOOK_PDO_SQLITE makes the PDO_SQLITE driver coroutine-friendly. This flag is available only when Swoole is installed with option "--enable-swoole-sqlite" included.
*
* @since 5.1.0
*/
define('SWOOLE_HOOK_PDO_SQLITE', 524288); // 2^19
/*
* There are two different hook flags for PHP's cURL functions:
* - SWOOLE_HOOK_CURL: Implemented by replacing PHP's cURL functions internally with swoole_curl_*() functions from Swoole Library.
Expand Down

0 comments on commit 77a57f2

Please sign in to comment.