Skip to content

Commit

Permalink
#40: updates for Swoole v6.0.0
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 cd1f2a1 commit b27ff35
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 114 deletions.
26 changes: 23 additions & 3 deletions src/swoole/Swoole/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ class Server
*/
public bool $ssl = false;

public $mode = 0;
/**
* Server mode. Must be either SWOOLE_BASE, SWOOLE_PROCESS, or SWOOLE_THREAD.
*
* Starting from Swoole 5.0.0, default server mode has been changed from SWOOLE_PROCESS to SWOOLE_BASE.
*
* Mode SWOOLE_THREAD is supported since 6.0.0. It is available only when PHP is compiled with Zend Thread Safety
* (ZTS) enabled and Swoole is installed with the "--enable-swoole-thread" configuration option.
*
* @see SWOOLE_BASE
* @see SWOOLE_PROCESS
* @see SWOOLE_THREAD
* @readonly
*/
public int $mode;

public $ports;

Expand All @@ -123,6 +136,14 @@ class Server
*/
public AdminServer $admin_server;

/**
* This property is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is
* installed with the "--enable-swoole-thread" configuration option.
*
* @since 6.0.0
*/
public string $bootstrap = '';

/**
* @var callable
*/
Expand Down Expand Up @@ -201,8 +222,7 @@ class Server
*
* @param string $host IP address of the network socket, or path of the UNIX domain socket bound to the primary port. For details, please check property \Swoole\Server::$host.
* @param int $port The primary port of the server. This parameter is ignored if $sock_type is SWOOLE_SOCK_UNIX_STREAM or SWOOLE_SOCK_UNIX_DGRAM.
* @param int $mode Must be either SWOOLE_BASE or SWOOLE_PROCESS. Starting from Swoole 5.0.0, default server mode has been
* changed from SWOOLE_PROCESS to SWOOLE_BASE.
* @param int $mode Server mode. Check property \Swoole\Server::$mode for details.
* @param int $sock_type Type of the socket. For details, please check property \Swoole\Server::$type.
*/
public function __construct(string $host = '0.0.0.0', int $port = 0, int $mode = SWOOLE_BASE, int $sock_type = SWOOLE_SOCK_TCP)
Expand Down
41 changes: 36 additions & 5 deletions src/swoole/Swoole/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,40 @@

namespace Swoole;

class Thread
/**
* Class \Swoole\Thread.
*
* 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.
*
* @since 6.0.0
*/
final class Thread
{
public int $id;
public const HARDWARE_CONCURRENCY = 12;

public const API_NAME = 'POSIX Threads';

public const SCHED_OTHER = 0;

public const SCHED_FIFO = 1;

public const SCHED_RR = 2;

public const SCHED_BATCH = 3;

public const SCHED_ISO = 4;

public const SCHED_IDLE = 5;

public const SCHED_DEADLINE = 6;

/**
* Thread ID. Default is 0.
*
* @readonly
*/
public int $id = 0;

public function __construct(string $script_file, mixed ...$args)
{
Expand Down Expand Up @@ -52,15 +83,15 @@ public static function getAffinity(): array
{
}

public function setPriority(int $priority, int $policy = 0): bool
public static function setPriority(int $priority, int $policy = 0): bool
{
}

public function getPriority(): array
public static function getPriority(): array
{
}

public function getNativeId(): int
public static function getNativeId(): int
{
}
}
23 changes: 15 additions & 8 deletions src/swoole/Swoole/Thread/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

namespace Swoole\Thread;

use ArrayAccess;
use Countable;

class ArrayList implements ArrayAccess, Countable
/**
* Class \Swoole\Thread\ArrayList.
*
* 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.
*
* @since 6.0.0
*/
final class ArrayList implements \ArrayAccess, \Countable
{
public int $id = 0;

public function __construct(?array $array = null)
{
}
Expand All @@ -33,10 +40,6 @@ public function find(mixed $value): int
{
}

public function count(): int
{
}

public function incr(mixed $key, mixed $value = 1): mixed
{
}
Expand All @@ -49,6 +52,10 @@ public function clean(): void
{
}

public function count(): int
{
}

public function toArray(): array
{
}
Expand Down
17 changes: 12 additions & 5 deletions src/swoole/Swoole/Thread/Atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

namespace Swoole\Thread;

class Atomic
/**
* Class \Swoole\Thread\Atomic.
*
* 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.
*
* @since 6.0.0
*/
final class Atomic
{
public function __construct(int $value = 0)
{
Expand All @@ -26,16 +34,15 @@ public function set(int $value): void
{
}

public function cmpset(int $cmp_value, int $new_value): bool
public function wait(float $timeout = 1): bool
{
}

public function wait(float $timeout = 1.0): bool
public function wakeup(int $count = 1): bool
{
}

public function wakeup(int $count = 1): bool
public function cmpset(int $cmp_value, int $new_value): bool
{
}
}

11 changes: 9 additions & 2 deletions src/swoole/Swoole/Thread/Atomic/Long.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

namespace Swoole\Thread\Atomic;

class Long
/**
* Class \Swoole\Thread\Atomic\Long.
*
* 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.
*
* @since 6.0.0
*/
final class Long
{
public function __construct(int $value = 0)
{
Expand All @@ -30,4 +38,3 @@ public function cmpset(int $cmp_value, int $new_value): bool
{
}
}

11 changes: 9 additions & 2 deletions src/swoole/Swoole/Thread/Barrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

namespace Swoole\Thread;

class Barrier
/**
* Class \Swoole\Thread\Barrier.
*
* 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.
*
* @since 6.0.0
*/
final class Barrier
{
public function __construct(int $count)
{
Expand All @@ -14,4 +22,3 @@ public function wait(): void
{
}
}

21 changes: 21 additions & 0 deletions src/swoole/Swoole/Thread/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Swoole\Thread;

/**
* Class \Swoole\Thread\Error.
*
* 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.
*
* @since 6.0.0
*/
class Error
{
/**
* Error code. Default is 0.
*/
public int $code = 0;
}
23 changes: 19 additions & 4 deletions src/swoole/Swoole/Thread/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@

namespace Swoole\Thread;

class Lock
/**
* Class \Swoole\Thread\Lock.
*
* 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.
*
* @since 6.0.0
*/
final class Lock
{
public function __construct(int $type = SWOOLE_MUTEX)
public const RWLOCK = 1;

public const MUTEX = 3;

public const SPINLOCK = 5;

public $errCode = 0;

public function __construct(int $type = 3)
{
}

Expand All @@ -18,7 +34,7 @@ public function lock(): bool
{
}

public function locakwait(float $timeout = 1.0): bool
public function lockwait(float $timeout = 1): bool
{
}

Expand All @@ -38,4 +54,3 @@ public function unlock(): bool
{
}
}

28 changes: 16 additions & 12 deletions src/swoole/Swoole/Thread/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

namespace Swoole\Thread;

use ArrayAccess;
use Countable;

class Map implements ArrayAccess, Countable
/**
* Class \Swoole\Thread\Map.
*
* 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.
*
* @since 6.0.0
*/
final class Map implements \ArrayAccess, \Countable
{
public function __construct(?array $array = null)
{
Expand Down Expand Up @@ -37,36 +42,35 @@ public function count(): int
{
}

public function keys(): array
public function incr(mixed $key, mixed $value = 1): mixed
{
}

public function values(): array
public function decr(mixed $key, mixed $value = 1): mixed
{
}

public function incr(mixed $key, mixed $value = 1): mixed
public function add(mixed $key, mixed $value): bool
{
}

public function decr(mixed $key, mixed $value = 1): mixed
public function update(mixed $key, mixed $value): bool
{
}

public function add(mixed $key, mixed $value): bool
public function clean(): void
{
}

public function update(mixed $key, mixed $value): bool
public function keys(): array
{
}

public function clean(): void
public function values(): array
{
}

public function toArray(): array
{
}
}

Loading

0 comments on commit b27ff35

Please sign in to comment.