Search by

swow / swow

twosee

Coroutine-based multi-platform support engine with a focus on concurrent I/O

Package info

github.com/swow/swow

Language:C

pkg:composer/swow/swow

Statistics

Installs: 2 373 600

Dependents: 118

Suggesters: 233

Stars: 1 333

Open Issues: 32


README

English | 简体中文 | 繁體中文 | 日本語 | Português | Русский

Swow Logo
🚀 Swow is a multi-platform, coroutine-based engine focused on concurrent I/O

license ci codecov release ❤️ php platform architecture

👾 Design Philosophy

Swow is committed to using the smallest C core and most of the PHP code to support PHP high-performance network programming, which determines that it is more about providing powerful secondary development capabilities by seamlessly integrating PHP code and C kernel, while ensuring critical performance.

In addition, it provides a variety of debugging mechanisms and powerful and low-threshold debugging tools, which can ensure that developers are free from the trouble of BUGs as much as possible, and ordinary developers can also have the ability to debug near the level of experts with the help of tools, so as to maximize development efficiency.

✨ Features

Write plain, blocking-style PHP. Swow makes it concurrent, and since 2.0 it runs on every CPU core.

Capability What you get
🧶 Coroutines you fully control Stackful Coroutine with Channel, WaitGroup, WaitReference, Selector and Defer. Inspect, interrupt or kill any coroutine at any time
🪄 Your existing code, now concurrent All of the following, and more, yield to other coroutines instead of blocking the process. No code changes:
Timers: sleep(), usleep(), time_nanosleep(), time_sleep_until()
DNS: gethostbyname(), gethostbynamel(), gethostbyaddr(), dns_get_record(), dns_get_mx(), dns_check_record()
Files and pipes: fopen(), fread(), fwrite(), file_get_contents(), flock() and the other file functions
PHP streams: TCP, UDP, Unix sockets and TLS, including fsockopen(), stream_socket_client(), stream_socket_server(), stream_select() and file_get_contents() over HTTP(S)
cURL: curl_exec(), curl_multi_* and HTTP/2, which covers Guzzle and other cURL-based HTTP clients
MySQL: PDO MySQL and mysqli, through mysqlnd
PostgreSQL: PDO PgSQL
MongoDB 2.0: the official mongodb extension
Redis: clients built on PHP streams, such as phpredis and Predis
Child processes: proc_open()
And more: any extension or pure-PHP library built on the above
🌐 A complete networking stack Socket covers TCP, UDP, Unix sockets, pipes and TLS, with built-in HTTP and WebSocket parsers, plus PSR-7 compatible HTTP and WebSocket servers and clients written in PHP
🧵 Real multi-threading 2.0 Thread runs PHP on OS threads, with Thannel (a cross-thread channel), Mutex, Semaphore, Futex, SharedBuffer (shared memory), and a ThreadManager for worker threads. Requires a thread-safe PHP build
🏭 Multi-processing on every OS 2.0 ChildProcess and a ProcessManager that restarts and reloads workers, on Windows too
🍃 Coroutine-aware MongoDB driver 2.0 The official mongodb extension does its I/O asynchronously and no longer blocks the process. Build with --enable-swow-mongodb
🐞 SDB, the Swow Debugger An interactive debugger written in PHP with gdb-style commands: list every coroutine, read backtraces and source, set breakpoints, step through code and print variables
🐶 Watchdog Catches coroutines that hog the CPU or block in a system call. It can make the offender yield to the others, or hand it to your callback to suspend or kill it
🔬 More debugging tools Deadlock detection and execution tracing

See everything new in 2.0 in the CHANGELOG.

🎮 Installation

Like any open source project, Swow always provides the strongest stability and features in the newest release, please try to ensure that you are using the latest version.

🔎 Requirements

  • Common operating systems such as Linux, Windows, macOS, etc. Almost same as libuv
  • PHP 8.0.0 or above, the latest version is recommended
  • A thread-safe (ZTS) build of PHP if you want to use the multi-thread facilities

🥧 Using PIE

Get PIE first.

pie install swow/swow-extension

for develop version (may contain bugfix):

pie install swow/swow-extension:dev-develop

👨‍🎤 By Composer

pull source code:

composer require swow/swow

Then run the automatic installer swow-builder under the vendor/bin directory to start the installation:

./vendor/bin/swow-builder --install

After you update the source code of Swow, you should use the rebuild option to recompile Swow and then install it:

./vendor/bin/swow-builder --rebuild --install

More information about swow-builder can be found in Extension installation document - By Composer.

🐧 Manual installation (UNIX-like)

clone the Swow (You can also import it through Composer, and then cd to vendor/swow/swow/ext and install manually):

git clone https://github.com/swow/swow.git

Well-known building procedure. Install to the system with root privileges:

cd swow/ext && \
phpize && ./configure && \
make clean && make -j && \
sudo make install

See Installation document - Manual compilation installation (UNIX-like).

Ⓜ️ Manual installation (Windows)

See Installation document - Manual compilation installation (Windows).

You can also download DLL directly in Latest Release.

🔰️ Security issues

Security issues should be reported privately, via email, to twosee@php.net. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.

🖊️ Contribution

Your contribution to Swow development is very welcome!

You may contribute in the following ways:

❤️ Contributors

Building a high-performance coroutine network engine for PHP is a tune pitched so high that few can sing along. It is open source work where it is lonely at the top.

Many thanks to the following friends for their code contributions to the Swow project. Without you, there would be no Swow today.

Contributors

💬 Development & Discussion

📃 License

Swow is available under the Apache License Version 2.0. Swow also includes external libraries that are available under a variety of licenses. See LICENSES.full for the full license text.