Reseller Login or Sign up FAQ Search
ResellersPanel's Blog

Swoole – a popular PHP network framework, has been enabled on our platform

Swoole PHP network frameworkIn recent years, Swoole has taken over as the new best programming solution thanks to its scalability and to the performance boosting capabilities it boasts as a PHP extension.

Swoole represents an event-driven network communication framework for asynchronous and parallel PHP requests, which is aimed at scaling up the performance of web applications.

Based on the C language exclusively, Swoole allows PHP developers to write scalable applications for: Internet, mobile communication, cloud computing, online gaming, without the need to have an in-depth knowledge of non-blocking I/O programming.

Learn more about the Swoole framework and about how you can make use of it on our web hosting platform.

What is the Swoole framework about?

Swoole was introduced with one basic idea in mind – to provide efficiency to PHP programmers and give them more time to focus their efforts on more innovative products.

Swoole boasts built-in async, multi-threadеd I/O (input/output) modules, which distinguish it from the other async programming frameworks such as Nginx and Node.js.

This allows programmers to create network servers and to perform database and filesystem operations for the PHP language.

PHP developers can use either sync or async API to write the applications.

Here is a glimpse of the advantages of the Swoole framework:

  • 100% C-compiled, with extremely powerful performance;
  • Simple and easy to use, development-efficient;
  • Event-driven, non-blocking asynchronous processing;
  • Supports millions of concurrent TCP connections;
  • Supports asynchronous/synchronous/coroutine;
  • Supports multiprocessing/multi-threading;
  • CPU affinity/daemon process;

And here is a list of the key Swoole components, which make Swoole truly efficient for application development:

  • IPv4 / IPv6 / Unixsocket network support;
  • Async TCP/UDP server and client;
  • SSL / TLS support;
  • Async HTTP/ WebSocket client;
  • Database connection pooling;
  • Async MySQL client;
  • Async Redis Client;
  • Fast Serializer / Unserializer;
  • Milliseconds task scheduler;

With this wide array of components, Swoole can be utilized by a number of applications for mobile communication, cloud computing, microservices, mobile games, and live chat systems, to name a few, which are normally within the capacity of C++ or Java developers.

Currently, Swoole is adopted by some of the greatest retail platforms like Alibaba and Baidu.

How does the Swoole framework work?

Swoole runs in CLI mode, which distinguishes it from the common PHP model.

Swoole PHP model

Here are the key differences between Swoole and the traditional PHP model:

  • Swoole supports more server-side protocols;
  • Swoole supports long-live connections for websocket/TCP/UDP server;
  • Swoole creates additional worker processes so as to make use of all available CPU cores;
  • Swoole can manage and re-use the status in memory.

How to make use of Swoole on our platform?

The Swoole extension has been readily installed on our web hosting platform and you can enable it with a click for your projects.

In the PHP settings section of the Hepsia Control Panel, just scroll down to the Swoole setting at the bottom of the table and click on the pertaining checkbox.

Swoole network framework - enable from Control Panel

NOTE: The Swoole extension is currently supported by the PHP 7 version only, so make sure to switch to any of the supported PHP 7 releases first. 

Swoole network framework - only for php 7 versions

Once you have enabled Swoole for your hosting account, you will need to create an instance for your project from the Supervisor section. 

In the Supervisor section, just click on the Create Instance button and then specify the path to the script you want to use Swoole for:

Swoole network framework - create supervisor instance

In our example, we are using a websocket server script:

Swoole network framework - websocket server example

Once the instance has been added, you will need to copy the port that has been generated for the instance:

Swoole network framework - supervisor instance port

and paste it into the script file as displayed below:

Swoole network framework - replace port in websocket script

That’s it! Now you will be able to run a websocket server by using the Swoole network framework on our platform. 

Originally published Friday, August 10th, 2018 at 1:36 pm, updated August 14, 2018 and is filed under Hepsia Control Panel.

Tags: , , ,

Leave a Reply


« Back to menu