Skip to content

Commit b27ff35

Browse files
committed
#40: updates for Swoole v6.0.0
Signed-off-by: Demin Yin <[email protected]>
1 parent cd1f2a1 commit b27ff35

File tree

12 files changed

+177
-114
lines changed

12 files changed

+177
-114
lines changed

src/swoole/Swoole/Server.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ class Server
9696
*/
9797
public bool $ssl = false;
9898

99-
public $mode = 0;
99+
/**
100+
* Server mode. Must be either SWOOLE_BASE, SWOOLE_PROCESS, or SWOOLE_THREAD.
101+
*
102+
* Starting from Swoole 5.0.0, default server mode has been changed from SWOOLE_PROCESS to SWOOLE_BASE.
103+
*
104+
* Mode SWOOLE_THREAD is supported since 6.0.0. It is available only when PHP is compiled with Zend Thread Safety
105+
* (ZTS) enabled and Swoole is installed with the "--enable-swoole-thread" configuration option.
106+
*
107+
* @see SWOOLE_BASE
108+
* @see SWOOLE_PROCESS
109+
* @see SWOOLE_THREAD
110+
* @readonly
111+
*/
112+
public int $mode;
100113

101114
public $ports;
102115

@@ -123,6 +136,14 @@ class Server
123136
*/
124137
public AdminServer $admin_server;
125138

139+
/**
140+
* This property is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is
141+
* installed with the "--enable-swoole-thread" configuration option.
142+
*
143+
* @since 6.0.0
144+
*/
145+
public string $bootstrap = '';
146+
126147
/**
127148
* @var callable
128149
*/
@@ -201,8 +222,7 @@ class Server
201222
*
202223
* @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.
203224
* @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.
204-
* @param int $mode Must be either SWOOLE_BASE or SWOOLE_PROCESS. Starting from Swoole 5.0.0, default server mode has been
205-
* changed from SWOOLE_PROCESS to SWOOLE_BASE.
225+
* @param int $mode Server mode. Check property \Swoole\Server::$mode for details.
206226
* @param int $sock_type Type of the socket. For details, please check property \Swoole\Server::$type.
207227
*/
208228
public function __construct(string $host = '0.0.0.0', int $port = 0, int $mode = SWOOLE_BASE, int $sock_type = SWOOLE_SOCK_TCP)

src/swoole/Swoole/Thread.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,40 @@
44

55
namespace Swoole;
66

7-
class Thread
7+
/**
8+
* Class \Swoole\Thread.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
final class Thread
816
{
9-
public int $id;
17+
public const HARDWARE_CONCURRENCY = 12;
18+
19+
public const API_NAME = 'POSIX Threads';
20+
21+
public const SCHED_OTHER = 0;
22+
23+
public const SCHED_FIFO = 1;
24+
25+
public const SCHED_RR = 2;
26+
27+
public const SCHED_BATCH = 3;
28+
29+
public const SCHED_ISO = 4;
30+
31+
public const SCHED_IDLE = 5;
32+
33+
public const SCHED_DEADLINE = 6;
34+
35+
/**
36+
* Thread ID. Default is 0.
37+
*
38+
* @readonly
39+
*/
40+
public int $id = 0;
1041

1142
public function __construct(string $script_file, mixed ...$args)
1243
{
@@ -52,15 +83,15 @@ public static function getAffinity(): array
5283
{
5384
}
5485

55-
public function setPriority(int $priority, int $policy = 0): bool
86+
public static function setPriority(int $priority, int $policy = 0): bool
5687
{
5788
}
5889

59-
public function getPriority(): array
90+
public static function getPriority(): array
6091
{
6192
}
6293

63-
public function getNativeId(): int
94+
public static function getNativeId(): int
6495
{
6596
}
6697
}

src/swoole/Swoole/Thread/ArrayList.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
namespace Swoole\Thread;
66

7-
use ArrayAccess;
8-
use Countable;
9-
10-
class ArrayList implements ArrayAccess, Countable
7+
/**
8+
* Class \Swoole\Thread\ArrayList.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
final class ArrayList implements \ArrayAccess, \Countable
1116
{
17+
public int $id = 0;
18+
1219
public function __construct(?array $array = null)
1320
{
1421
}
@@ -33,10 +40,6 @@ public function find(mixed $value): int
3340
{
3441
}
3542

36-
public function count(): int
37-
{
38-
}
39-
4043
public function incr(mixed $key, mixed $value = 1): mixed
4144
{
4245
}
@@ -49,6 +52,10 @@ public function clean(): void
4952
{
5053
}
5154

55+
public function count(): int
56+
{
57+
}
58+
5259
public function toArray(): array
5360
{
5461
}

src/swoole/Swoole/Thread/Atomic.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
namespace Swoole\Thread;
66

7-
class Atomic
7+
/**
8+
* Class \Swoole\Thread\Atomic.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
final class Atomic
816
{
917
public function __construct(int $value = 0)
1018
{
@@ -26,16 +34,15 @@ public function set(int $value): void
2634
{
2735
}
2836

29-
public function cmpset(int $cmp_value, int $new_value): bool
37+
public function wait(float $timeout = 1): bool
3038
{
3139
}
3240

33-
public function wait(float $timeout = 1.0): bool
41+
public function wakeup(int $count = 1): bool
3442
{
3543
}
3644

37-
public function wakeup(int $count = 1): bool
45+
public function cmpset(int $cmp_value, int $new_value): bool
3846
{
3947
}
4048
}
41-

src/swoole/Swoole/Thread/Atomic/Long.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
namespace Swoole\Thread\Atomic;
66

7-
class Long
7+
/**
8+
* Class \Swoole\Thread\Atomic\Long.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
final class Long
816
{
917
public function __construct(int $value = 0)
1018
{
@@ -30,4 +38,3 @@ public function cmpset(int $cmp_value, int $new_value): bool
3038
{
3139
}
3240
}
33-

src/swoole/Swoole/Thread/Barrier.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
namespace Swoole\Thread;
66

7-
class Barrier
7+
/**
8+
* Class \Swoole\Thread\Barrier.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
final class Barrier
816
{
917
public function __construct(int $count)
1018
{
@@ -14,4 +22,3 @@ public function wait(): void
1422
{
1523
}
1624
}
17-

src/swoole/Swoole/Thread/Error.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Swoole\Thread;
6+
7+
/**
8+
* Class \Swoole\Thread\Error.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
class Error
16+
{
17+
/**
18+
* Error code. Default is 0.
19+
*/
20+
public int $code = 0;
21+
}

src/swoole/Swoole/Thread/Lock.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,25 @@
44

55
namespace Swoole\Thread;
66

7-
class Lock
7+
/**
8+
* Class \Swoole\Thread\Lock.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
final class Lock
816
{
9-
public function __construct(int $type = SWOOLE_MUTEX)
17+
public const RWLOCK = 1;
18+
19+
public const MUTEX = 3;
20+
21+
public const SPINLOCK = 5;
22+
23+
public $errCode = 0;
24+
25+
public function __construct(int $type = 3)
1026
{
1127
}
1228

@@ -18,7 +34,7 @@ public function lock(): bool
1834
{
1935
}
2036

21-
public function locakwait(float $timeout = 1.0): bool
37+
public function lockwait(float $timeout = 1): bool
2238
{
2339
}
2440

@@ -38,4 +54,3 @@ public function unlock(): bool
3854
{
3955
}
4056
}
41-

src/swoole/Swoole/Thread/Map.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55
namespace Swoole\Thread;
66

7-
use ArrayAccess;
8-
use Countable;
9-
10-
class Map implements ArrayAccess, Countable
7+
/**
8+
* Class \Swoole\Thread\Map.
9+
*
10+
* This class is available only when PHP is compiled with Zend Thread Safety (ZTS) enabled and Swoole is installed with
11+
* the "--enable-swoole-thread" configuration option.
12+
*
13+
* @since 6.0.0
14+
*/
15+
final class Map implements \ArrayAccess, \Countable
1116
{
1217
public function __construct(?array $array = null)
1318
{
@@ -37,36 +42,35 @@ public function count(): int
3742
{
3843
}
3944

40-
public function keys(): array
45+
public function incr(mixed $key, mixed $value = 1): mixed
4146
{
4247
}
4348

44-
public function values(): array
49+
public function decr(mixed $key, mixed $value = 1): mixed
4550
{
4651
}
4752

48-
public function incr(mixed $key, mixed $value = 1): mixed
53+
public function add(mixed $key, mixed $value): bool
4954
{
5055
}
5156

52-
public function decr(mixed $key, mixed $value = 1): mixed
57+
public function update(mixed $key, mixed $value): bool
5358
{
5459
}
5560

56-
public function add(mixed $key, mixed $value): bool
61+
public function clean(): void
5762
{
5863
}
5964

60-
public function update(mixed $key, mixed $value): bool
65+
public function keys(): array
6166
{
6267
}
6368

64-
public function clean(): void
69+
public function values(): array
6570
{
6671
}
6772

6873
public function toArray(): array
6974
{
7075
}
7176
}
72-

0 commit comments

Comments
 (0)