From 86a61562a1f1634339ee52f3b8988591f51a2799 Mon Sep 17 00:00:00 2001 From: Demin Yin Date: Fri, 3 Jan 2025 11:08:24 -0800 Subject: [PATCH] updates for Swoole v6.0.0 Signed-off-by: Demin Yin --- src/swoole/Swoole/Async/Client.php | 43 +++++++----------------- src/swoole/Swoole/Atomic.php | 3 +- src/swoole/Swoole/Atomic/Long.php | 3 +- src/swoole/Swoole/Client.php | 7 +++- src/swoole/Swoole/Lock.php | 1 + src/swoole/Swoole/Process.php | 12 +++++++ src/swoole/Swoole/Thread.php | 27 +++++++++++++++ src/swoole/Swoole/Thread/Atomic.php | 5 +++ src/swoole/Swoole/Thread/Atomic/Long.php | 5 +++ src/swoole/Swoole/Thread/Lock.php | 4 +++ 10 files changed, 77 insertions(+), 33 deletions(-) diff --git a/src/swoole/Swoole/Async/Client.php b/src/swoole/Swoole/Async/Client.php index 7b5eeee..93b1732 100644 --- a/src/swoole/Swoole/Async/Client.php +++ b/src/swoole/Swoole/Async/Client.php @@ -9,20 +9,6 @@ */ class Client extends \Swoole\Client { - public const MSG_OOB = 1; - - public const MSG_PEEK = 2; - - public const MSG_DONTWAIT = 64; - - public const MSG_WAITALL = 256; - - public const SHUT_RDWR = 2; - - public const SHUT_RD = 0; - - public const SHUT_WR = 1; - private $onConnect; private $onError; @@ -37,18 +23,13 @@ class Client extends \Swoole\Client private $onSSLReady; + /** + * @param int $type Socket type. Please check comments on property \Swoole\Client::$type for more details. + */ public function __construct(int $type) { } - public function __destruct() - { - } - - public function connect(string $host, int $port = 0, float $timeout = 0.5, int $sock_flag = 0): bool - { - } - public function sleep(): bool { } @@ -65,18 +46,20 @@ public function resume(): bool { } + /** + * Enable SSL encryption on the connection. + * + * This method is available only when OpenSSL support is enabled (i.e., when Swoole is installed with configuration + * option "--enable-openssl" included). + * + * {@inheritDoc} + * @param callable|null $onSslReady Callback function to be executed when SSL handshake is successful. + * @return bool TRUE if SSL handshake is successful; otherwise FALSE. + */ public function enableSSL(?callable $onSslReady = null): bool { } - public function isConnected(): bool - { - } - - public function close(bool $force = false): bool - { - } - public function on(string $host, callable $callback): bool { } diff --git a/src/swoole/Swoole/Atomic.php b/src/swoole/Swoole/Atomic.php index 55e38f0..e206ce9 100644 --- a/src/swoole/Swoole/Atomic.php +++ b/src/swoole/Swoole/Atomic.php @@ -17,7 +17,8 @@ * This class uses unsigned 32-bit integers to store the value. To store the value using signed 64-bit integers, use class * \Swoole\Atomic\Long instead. Note that class \Swoole\Atomic\Long doesn't have method wait() nor wakeup() implemented. * - * @see \Swoole\Atomic\Long + * @see \Swoole\Thread\Atomic Use this instead when PHP is compiled with Zend Thread Safety (ZTS) enabled. + * @see \Swoole\Atomic\Long Use this instead to store the value using signed 64-bit integers instead of unsigned 32-bit integers. * @not-serializable Objects of this class cannot be serialized. */ class Atomic diff --git a/src/swoole/Swoole/Atomic/Long.php b/src/swoole/Swoole/Atomic/Long.php index 0a13f32..0fdbc67 100644 --- a/src/swoole/Swoole/Atomic/Long.php +++ b/src/swoole/Swoole/Atomic/Long.php @@ -17,7 +17,8 @@ * This class uses signed 64-bit integers to store the value. To store the value using unsigned 32-bit integers, use * class \Swoole\Atomic instead. * - * @see \Swoole\Atomic + * @see \Swoole\Thread\Atomic\Long Use this instead when PHP is compiled with Zend Thread Safety (ZTS) enabled. + * @see \Swoole\Atomic Use this instead to store the value using unsigned 32-bit integers instead of signed 64-bit integers. * @not-serializable Objects of this class cannot be serialized. */ class Long diff --git a/src/swoole/Swoole/Client.php b/src/swoole/Swoole/Client.php index 1635370..f45ebaf 100644 --- a/src/swoole/Swoole/Client.php +++ b/src/swoole/Swoole/Client.php @@ -115,12 +115,17 @@ public function shutdown(int $how): bool } /** + * Enable SSL encryption on the connection. + * * This method is available only when OpenSSL support is enabled (i.e., when Swoole is installed with configuration * option "--enable-openssl" included). * + * @param callable|null $onSslReady Callback function to be executed when SSL handshake is successful. + * Added in v6.0.0-rc1 for child class Swoole\Async\Client only. It has no effect + * on this class. * @return bool TRUE if SSL handshake is successful; otherwise FALSE. */ - public function enableSSL(): bool + public function enableSSL(?callable $onSslReady = null): bool { } diff --git a/src/swoole/Swoole/Lock.php b/src/swoole/Swoole/Lock.php index efa622e..87649c4 100644 --- a/src/swoole/Swoole/Lock.php +++ b/src/swoole/Swoole/Lock.php @@ -30,6 +30,7 @@ * * If you think you need to use locks with coroutines, you can probably use channels instead. * + * @see \Swoole\Thread\Lock Use this instead when PHP is compiled with Zend Thread Safety (ZTS) enabled. * @see https://github.com/deminy/swoole-by-examples/blob/master/examples/csp/deadlocks/swoole-lock.php * @not-serializable Objects of this class cannot be serialized. */ diff --git a/src/swoole/Swoole/Process.php b/src/swoole/Swoole/Process.php index f95cd33..f515242 100644 --- a/src/swoole/Swoole/Process.php +++ b/src/swoole/Swoole/Process.php @@ -29,6 +29,8 @@ class Process /** * Process ID. This is to uniquely identify the process in the OS. + * + * @readonly */ public int $pid; @@ -38,11 +40,21 @@ class Process * In a Swoole program (e.g., a Swoole-based server), there are different types of processes, including event worker * processes, task worker processes, and user worker processes. This ID is to uniquely identify the process in the * running Swoole program. + * + * @readonly */ public int $id; + /** + * @var callable The callback function of the process. + */ private $callback; + /** + * The constructor. + * + * @param callable $callback The callback function of the process. + */ public function __construct(callable $callback, bool $redirect_stdin_and_stdout = false, int $pipe_type = 2, bool $enable_coroutine = false) { } diff --git a/src/swoole/Swoole/Thread.php b/src/swoole/Swoole/Thread.php index bda29a5..4802cd1 100644 --- a/src/swoole/Swoole/Thread.php +++ b/src/swoole/Swoole/Thread.php @@ -14,6 +14,12 @@ */ final class Thread { + /** + * The number of concurrent threads supported by the hardware. + * + * Note that value of this constant is system- and implementation- specific, and may not be exact, but just an + * approximation. The actual value on your machine could be smaller or (much) larger than the number hardcoded here. + */ public const HARDWARE_CONCURRENCY = 12; public const API_NAME = 'POSIX Threads'; @@ -71,6 +77,13 @@ public static function getInfo(): array { } + /** + * Set the name of the thread. + * + * @param string $name The name of the thread. + * @return bool TRUE on success, or FALSE on failure. + * @see https://linux.die.net/man/3/pthread_setname_np + */ public static function setName(string $name): bool { } @@ -102,10 +115,24 @@ public static function getAffinity(): array { } + /** + * set scheduling policy and priority of a thread. + * + * @return bool Returns true on success or false on failure. + * @see \Swoole\Swoole::getPriority() + * @see https://linux.die.net/man/3/pthread_setschedparam + */ public static function setPriority(int $priority, int $policy = 0): bool { } + /** + * Get scheduling policy and parameters of a thread. + * + * @return array{policy: int, priority: int} An array containing the scheduling policy and priority of the thread. + * @see \Swoole\Swoole::setPriority() + * @see https://linux.die.net/man/3/pthread_getschedparam + */ public static function getPriority(): array { } diff --git a/src/swoole/Swoole/Thread/Atomic.php b/src/swoole/Swoole/Thread/Atomic.php index 56f1a15..5f83360 100644 --- a/src/swoole/Swoole/Thread/Atomic.php +++ b/src/swoole/Swoole/Thread/Atomic.php @@ -10,7 +10,12 @@ * This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with * the "--enable-swoole-thread" configuration option. * + * This class is a thread-safe version of the \Swoole\Atomic class. For more information, see the documentation for the + * \Swoole\Atomic class. + * * @since 6.0.0 + * @see \Swoole\Atomic Use this instead when PHP is compiled without Zend Thread Safety (ZTS) enabled. + * @see \Swoole\Thread\Atomic\Long Use this instead to store the value using signed 64-bit integers instead of unsigned 32-bit integers. */ final class Atomic { diff --git a/src/swoole/Swoole/Thread/Atomic/Long.php b/src/swoole/Swoole/Thread/Atomic/Long.php index f5c505c..27f71f5 100644 --- a/src/swoole/Swoole/Thread/Atomic/Long.php +++ b/src/swoole/Swoole/Thread/Atomic/Long.php @@ -10,7 +10,12 @@ * This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with * the "--enable-swoole-thread" configuration option. * + * This class is a thread-safe version of the \Swoole\Atomic\Long class. For more information, see the documentation for + * the \Swoole\Atomic\Long class. + * * @since 6.0.0 + * @see \Swoole\Atomic\Long Use this instead when PHP is compiled without Zend Thread Safety (ZTS) enabled. + * @see \Swoole\Thread\Atomic Use this instead to store the value using unsigned 32-bit integers instead of signed 64-bit integers. */ final class Long { diff --git a/src/swoole/Swoole/Thread/Lock.php b/src/swoole/Swoole/Thread/Lock.php index d538999..36c2065 100644 --- a/src/swoole/Swoole/Thread/Lock.php +++ b/src/swoole/Swoole/Thread/Lock.php @@ -10,6 +10,10 @@ * This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with * the "--enable-swoole-thread" configuration option. * + * This class is a thread-safe version of the \Swoole\Lock class. For more information, see the documentation for the + * \Swoole\Lock class. + * + * @see \Swoole\Lock Use this instead when PHP is compiled without Zend Thread Safety (ZTS) enabled. * @since 6.0.0 */ final class Lock