Swoole Multiprocessing

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Taking advantage of multicore, you have to use multiple processes in you server or application. You can build multiple processes application easily with the features provided by Swoole.

Create and manage multiple processes

Multiple processes can run simultaneously (without context-switching) in multi-core processors. You can create multiple Linux processes in several ways:

  1. Define and manage multiple Worker processes in Server.
  2. Define and manage multiple Task Worker processes in Server.
  3. Create and manage one process with Swoole Process.
  4. Create and manage multiple identical processes with Swoole Process Pool.
  5. Create and manage multiple processes with Swoole Process Manager.
  6. You can use fork or pcntl_fork.

Share data across multiple processes

  1. Use multiple process safe counter defined with Swoole Atomic.
  2. Use Swoole Table as in memory KV storage.

Interprocess synchronization

  1. Use Swoole Atomic wait and wakeup for synchronization.
  2. Use Swooel Lock for process synchronization.

Notice: process level synchronization should not be used within coroutine context

Last updated on August 31, 2022