Cara menggunakan swoole windows

Compared with other async programming frameworks or software such as Nginx, Tornado, Node.js, Open Swoole is a complete async solution that has built-in support for async programming via fibers/coroutines, a range of multi-threaded I/O modules (HTTP Server, WebSockets, GRPC, TaskWorkers, Process Pools) and support for popular PHP clients like PDO for MySQL, Redis and CURL.

You can use sync or async, coroutine, fiber API to write the applications or create thousands of light weight fibers within one Linux process.

Open Swoole enhances the efficiency of your PHP applications and brings you out of the traditional stateless model, enabling you to focus on the development of innovative products at high scale, bringing event loops and asynchronous programming to the PHP language.

Important: Please make sure you have followed the prerequisites guide before trying to install Open Swoole, this ensures you have an up-to-date system and all the required third-party packages and libraries.

docker pull openswoole/swoole

You can install Open Swoole binary releases via the Official Open Swoole Ubuntu PPA. For example, on Ubuntu or Debian:

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole

You can install Open Swoole binary releases via the Remi's RPM repository.

Install Epel and Remi Repo in RHEL:

# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package

Install Remi Repo in Fedora:

dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole

Open Swoole is released as a

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
5 package and can be installed using the command line from the binaries. This is the easiest and quickest way to get working with Open Swoole.

#!/bin/bash

# Make sure PECL is available...
$ sudo apt install php-dev

# Latest release of Open Swoole via PECL
$ sudo pecl install openswoole

Or to install a specific version using PECL:

#!/bin/bash
$ sudo pecl install openswoole-4.9.1

It is recommend to use Ubuntu on WSL to use Open Swoole on Windows.

You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.

wsl --install

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole

When installing Open Swoole via PECL, during the installation it will ask you if you would like to enable certain features, this can be provided before running the installation, this helps with automating the installation of Swoole or for when you don't want the installation to stop and wait for input. Some options require third party libraries to be installed, see prerequisites.

Shorthand Configure Flag

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
0

Longhand Configure Flag

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
1

Note The Open Swoole PECL releases is later than the GitHub releases

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
2
apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
3

Make sure to read the prerequisites first before compiling Swoole.

To compile and install the Swoole extension for PHP, we can clone the repository from GitHub where Swoole is developed, checkout the version you want to compile and manually install it.

Download the source package from GitHub Releases or clone from the git repository.

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
4

The script above will clone Open Swoole from GitHub, checkout v4.6.7 and setup Open Swoole ready to compile using

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
6. We then use
apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
7 to build Open Swoole with the options we want to enable, everything is then compiled using
apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
8 and
apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
9. You can choose which configuration options you need, see the for more information.

You may need to run

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
9 with
# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
1 privileges.

After installing the Swoole extension to the PHP extensions directory, you will need to enable Open Swoole so that PHP can load the extension when executing code.

Manually enabling Open Swoole via php.ini

On most systems Open Swoole can be enabled by directly editing your

# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
2 configuration file, you will want to add
# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
3 to the end of the file and then Open Swoole should be enabled.

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
5

Enabling Open Swoole via phpenmod

Some Linux distributions like Debian or Ubuntu use the PHP

# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
4 to load PHP extensions, in this case you can use
# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
5 to enable Swoole. Follow the commands below to get Swoole enabled.

Make sure to change

# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
6 to the version of PHP that you have installed.

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
6

You can also disable Open Swoole using

# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
7 if you need to (this is not uninstalling, just turning Swoole off):

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
7

These configuration options are used for enabling some features with Open Swoole, you can use these when installing via PECL or compiling from source.

Enable OpenSSL support. It depends on the

# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
8 library given by your operating system.

Set the path of OpenSSL library you want to use, for example:

# On RHEL/CentOS 8
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
yum update
yum --enablerepo=remi install package

#On RHEL/CentOS 7
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
yum --enablerepo=remi install package
9.

Enable the support of HTTP2. It depends on

dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
0 library which is built into Open Swoole for you. However, you have to enable this option still if you want HTTP2 support.

Enable native CURL hook support for OpenSwoole coroutines. Since v4.6.0 there is native support for CURL, you must have

dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
1 installed.

Enable Postgres Coroutine support.

Enable support for asynchronous DNS support, made possible by compiling the DNS library

dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
2. By default this feature is off, if
dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
2 is not enabled, async DNS queries within OpenSwoole are simulated with a pool of blocking processes to process.

Once

dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
2 is enabled in OpenSwoole, all the DNS queries produced by the OpenSwoole DNS API
dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
5,
dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
6 or OpenSwoole coroutine clients are asynchronous, including the MySQL client, Redis Client, HTTP Client, CURL etc. Also any DNS name resolves as well.

You have to install libc-ares before enabling this flag:

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
8

Enable support for

dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
7, for example this adds support for
dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
8. You must also install the PHP
dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-34.rpm   #[On Fedora 34]
dnf install http://rpms.remirepo.net/fedora/remi-release-33.rpm   #[On Fedora 33]
dnf install http://rpms.remirepo.net/fedora/remi-release-32.rpm   #[On Fedora 32]
yum --enablerepo=remi install package
7 module for this option to work. However, it is more recommended to use PHP PDO MySQL instead.

Or use

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
0 when you have postgres library installed at a custom location.

Enable support for

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
1, this adds support for Coroutine PostgreSQL Client

Enable sockets support. It depends on the PHP sockets extension. If this configuration has been enabled, the function

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
2 can add the connection created by the sockets extension to the event loop of Swoole. And the function
# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
3 depends on this configuration being enabled. However, the
# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
4 service can do most things and may be more recommended.

Turn on debugging mode for Swoole. You will need

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
5 installed to use this parameter.

Enable the debug logs of OpenSwoole. Don't enable this configuration in a production environment.

Turn on the trace log. After enabling this option, OpenSwoole will printout various details of the debug log, which is only used during kernel development.

Statically compile OpenSwoole and extend it to PHP. This option is only used when compiling PHP instead of OpenSwoole.

When a new OpenSwoole version is released, you can upgrade but it depends on how you installed OpenSwoole.

There is no need to uninstall OpenSwoole or delete any previous files, upgrading will overwrite any files or binaries, the install/upgrade process only produces one

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
6 binary for PHP to use.

For changelogs and updates, check out posts at https://openswoole.com/article/

If you installed via PECL, you can just run:

apt update
apt install -y software-properties-common && add-apt-repository ppa:ondrej/php -y
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
9

Or to install a specific version using PECL:

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
0

If you compiled OpenSwoole yourself from GitHub, you can recompile and install new changes/version again.

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
1

If you installed OpenSwoole via the Open Swoole Ubuntu PPA, you should receive updates via your package manager. For example, on Ubuntu or Debian:

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
2

If you are using a new version of PHP, perform a

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
7 to install the correct version.

If you are having difficulty installing or upgrading Swoole, first check the prerequisites guide but if that does not help, checkout the common installation errors for more help.

You can follow the instruction about how to debug segment fault errors with Swoole if you come across any.

apt update
apt install -y software-properties-common && add-apt-repository ppa:openswoole/ppa -y
# choose one PHP version:
#apt install -y php7.4-openswoole
#apt install -y php8.0-openswoole
apt install -y php8.1-openswoole
3

You have to install OpenSwoole Core composer library to access to a few features such as

# choose one PHP version:
#yum install php74-php-openswoole
#yum install php80-php-openswoole
yum install php81-php-openswoole
8 and addon functions implemented with PHP: