Skip to content

Commit

Permalink
updates for Swoole v6.0.0
Browse files Browse the repository at this point in the history
Signed-off-by: Demin Yin <deminy@deminy.net>
  • Loading branch information
deminy committed Jan 3, 2025
1 parent 9c1c50f commit 86a6156
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 33 deletions.
43 changes: 13 additions & 30 deletions src/swoole/Swoole/Async/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
}
Expand All @@ -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
{
}
Expand Down
3 changes: 2 additions & 1 deletion src/swoole/Swoole/Atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/swoole/Swoole/Atomic/Long.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/swoole/Swoole/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand Down
1 change: 1 addition & 0 deletions src/swoole/Swoole/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/swoole/Swoole/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Process

/**
* Process ID. This is to uniquely identify the process in the OS.
*
* @readonly
*/
public int $pid;

Expand All @@ -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)
{
}
Expand Down
27 changes: 27 additions & 0 deletions src/swoole/Swoole/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
{
}
Expand Down Expand Up @@ -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
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/swoole/Swoole/Thread/Atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 5 additions & 0 deletions src/swoole/Swoole/Thread/Atomic/Long.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions src/swoole/Swoole/Thread/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 86a6156

Please sign in to comment.