We've activated Swoole, a widely-used PHP network framework, on our platform

August 10, 2018
In recent years, Swoole has emerged as a leading programming solution due to its scalability and its ability to significantly enhance PHP performance as an extension.

Swoole serves as an event-driven network communication framework designed to handle asynchronous and parallel PHP requests, primarily focused on improving the performance of web applications.

Developed exclusively in C language, Swoole empowers PHP developers to create scalable applications for various purposes such as the internet, mobile communication, cloud computing, and online gaming, all without requiring an extensive understanding of non-blocking I/O programming.

To gain more insights into the Swoole framework and its utilization on our web hosting platform, please explore further.

What does the Swoole framework entail?

Swoole was conceived with a fundamental goal in mind: to enhance the efficiency of PHP programmers, allowing them more time for creative product development.

Swoole sets itself apart with its integrated asynchronous, multi-threaded I/O modules, distinguishing it from other asynchronous programming frameworks like Nginx and Node.js. These modules enable programmers to build network servers and execute database and filesystem operations for PHP.

PHP developers can choose between synchronous or asynchronous APIs for application development.

Here's a glimpse of the advantages offered by the Swoole framework:

  • Completely C-compiled for exceptional performance.
  • User-friendly, facilitating efficient development.
  • Event-driven architecture with non-blocking asynchronous processing.
  • Supports millions of concurrent TCP connections.
  • Enables asynchronous, synchronous, and coroutine programming.
  • Supports multiprocessing and multi-threading.
  • Offers CPU affinity and daemon process support.

Additionally, Swoole boasts key components that contribute to its efficiency in application development:

  • Support for IPv4, IPv6, and Unixsocket networks.
  • Asynchronous TCP/UDP server and client.
  • SSL/TLS support.
  • Asynchronous HTTP/WebSocket client.
  • Database connection pooling.
  • Asynchronous MySQL and Redis clients.
  • Fast serializer/unserializer.
  • Milliseconds task scheduler.

With this versatile set of components, Swoole finds application in various domains such as mobile communication, cloud computing, microservices, mobile games, and live chat systems—typically areas dominated by C++ or Java developers.

Notably, Swoole has gained adoption by prominent retail platforms like Alibaba and Baidu.

What is the operational mechanism of the Swoole framework?

Swoole operates in CLI mode, setting it apart from the typical PHP model.

Here are the fundamental distinctions between Swoole and the conventional PHP model:

  • 1. Swoole accommodates a wider range of server-side protocols.
  • 2. Swoole facilitates persistent connections for WebSocket, TCP, and UDP servers.
  • 3. Swoole generates extra worker processes to utilize all accessible CPU cores effectively.
  • 4. Swoole can efficiently manage and recycle status information in memory.

What are the steps for utilizing Swoole on our platform?

The Swoole extension is readily available on our web hosting platform, and you can activate it for your projects with a simple click.

To enable Swoole, navigate to the PHP settings section in the Hepsia Control Panel. Scroll down to find the Swoole setting located at the bottom of the table, and check the corresponding checkbox.

Please note that the Swoole extension is currently supported only for PHP 7 versions. Therefore, ensure that you switch to one of the supported PHP 7 releases beforehand.

Once you've enabled Swoole for your hosting account, you'll need to create an instance for your project in the Supervisor section. Within the Supervisor section, click on the "Create Instance" button, and then specify the path to the script for which you intend to use Swoole.

In our illustration, we're employing a WebSocket server script.

After you've successfully added the instance, you'll need to take note of the port generated for that instance and insert it into your script file.

That's all there is to it! You can now operate a WebSocket server on our platform using the Swoole network framework.