<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Evgeniy Panov</title>
    <description>The latest articles on DEV Community by Evgeniy Panov (@panov-eo).</description>
    <link>https://dev.to/panov-eo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3681682%2F7aa01748-8fb4-4406-92a0-f83cfbfbf418.png</url>
      <title>DEV Community: Evgeniy Panov</title>
      <link>https://dev.to/panov-eo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/panov-eo"/>
    <language>en</language>
    <item>
      <title>Setting Up React Project</title>
      <dc:creator>Evgeniy Panov</dc:creator>
      <pubDate>Mon, 24 Aug 2026 08:02:37 +0000</pubDate>
      <link>https://dev.to/panov-eo/setting-up-react-project-3dmn</link>
      <guid>https://dev.to/panov-eo/setting-up-react-project-3dmn</guid>
      <description>&lt;p&gt;I decided to write my own guide on React.&lt;/p&gt;

&lt;p&gt;In this section, we’ll set up a React project.&lt;/p&gt;

&lt;h2&gt;
  
  
  1 Download Node
&lt;/h2&gt;

&lt;p&gt;First, we need to install Node.js (if it’s not already installed). Download it from the official website: &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;https://nodejs.org/en&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2 Create a Project
&lt;/h2&gt;

&lt;p&gt;Open the terminal, navigate to the folder where you want to create the project, and run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm create vite@latest my_project -- --template react-ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let’s break down this command in more detail:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm&lt;/code&gt; is the Node.js package manager that runs the command.&lt;br&gt;
&lt;code&gt;create vite&lt;/code&gt; is a subcommand that launches the Vite project generator.&lt;br&gt;
&lt;code&gt;@latest&lt;/code&gt; is explicitly requests the use of the latest version of the create-vite package. This isn’t required (the latest version is installed by default), but it’s safer in case an older version is cached.&lt;br&gt;
&lt;code&gt;my_project&lt;/code&gt; - the name of the folder where the project will be created. After running the command, a directory with this name will appear. Of course, you can specify any name instead of &lt;code&gt;my_project&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;--&lt;/code&gt; is a separator. Anything that follows it is passed to the &lt;code&gt;create-vite&lt;/code&gt; script itself, rather than to npm, and is not interpreted as npm options.&lt;br&gt;
&lt;code&gt;--template react-ts&lt;/code&gt; is an argument for the generator: create a React project with TypeScript (&lt;code&gt;react-ts&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;TypeScript is a strongly typed programming language that compiles to JavaScript.&lt;/p&gt;

&lt;p&gt;Next, the terminal will prompt you to choose a linter. A linter is a program that checks your code for errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; Which linter to use?
&amp;gt; │ ● Oxlint
&amp;gt; │ ○ ESLint
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can choose either one.&lt;/p&gt;

&lt;p&gt;Next, you’ll be asked whether to run the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Install with npm and start now?
│  ● Yes / ○ No
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, let’s run it and make sure everything works&lt;/p&gt;

&lt;p&gt;Next, you’ll need to wait just a moment, and eventually you’ll see a message that looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;VITE v8.2.1  ready in 692 ms

➜  Local:   http://localhost:5173/
➜  Network: use --host to expose
➜  press h + enter to show help
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can navigate to the URL shown above.&lt;/p&gt;

&lt;p&gt;Hooray! We’ve just deployed the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Installing Tailwind CSS
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS is a CSS framework.&lt;/p&gt;

&lt;p&gt;Install it like this (don’t forget to navigate to the project folder, because we’re currently in its parent folder)&lt;br&gt;
&lt;code&gt;cd my_project&lt;/code&gt;&lt;br&gt;
&lt;code&gt;npm install -D tailwindcss @tailwindcss/vite&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Tailwind isn’t a CSS file; it’s a framework for generating CSS on the fly (more precisely, during the build phase).&lt;/p&gt;

&lt;p&gt;For example, it excludes unused CSS classes and supports special directives.&lt;/p&gt;

&lt;p&gt;To do this, you need to connect Tailwind to Vite; you can do this in the &lt;code&gt;vite.config.ts&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vitejs/plugin-react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;tailwindcss&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@tailwindcss/vite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nf"&gt;tailwindcss&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To apply the changes, you need to reload the dev server (stop it with &lt;code&gt;Ctrl+C&lt;/code&gt; and run &lt;code&gt;npm run dev&lt;/code&gt; again).&lt;/p&gt;

&lt;p&gt;But that’s not all—you need to include the generated CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Let’s connect TailwindCSS and clean up the project
&lt;/h2&gt;

&lt;p&gt;The CSS that will be generated needs to be imported into the src/index.css file (this is where all CSS files are consolidated).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"tailwindcss"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything else in this file should be deleted.&lt;/p&gt;

&lt;p&gt;This &lt;code&gt;index.css&lt;/code&gt; is already imported in &lt;code&gt;src/main.tsx&lt;/code&gt; (the application’s entry point).&lt;br&gt;
Make sure the following line is present there:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import './index.css'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;src/App.tsx&lt;/code&gt;, delete everything and insert the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete the &lt;code&gt;src/App.css&lt;/code&gt; file and the assets folder along with all its contents&lt;/p&gt;

&lt;h2&gt;
  
  
  5 Set up the favicon
&lt;/h2&gt;

&lt;p&gt;The final touch is to set up the site’s icon. I like &lt;a href="https://www.flaticon.com/" rel="noopener noreferrer"&gt;this&lt;/a&gt; site, it has lots of free icons. It requires you to credit the author, and I encourage you to do so, for example on the Credits page.&lt;/p&gt;

&lt;p&gt;After downloading the icon you like, name it &lt;code&gt;icon.png&lt;/code&gt; and place it in the folder &lt;code&gt;public/&lt;/code&gt;. Delete the other two files (&lt;code&gt;favicon.svg&lt;/code&gt; and &lt;code&gt;icons.svg&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Now go to index.html (located in the project root) and replace the line&lt;br&gt;
&lt;code&gt;&amp;lt;link rel="icon" type="image/svg+xml" href="/favicon.svg" /&amp;gt;&lt;/code&gt;&lt;br&gt;
with&lt;br&gt;
&lt;code&gt;&amp;lt;link rel="icon" type="image/png" href="/icon.png" /&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In some browsers, the icon may not update immediately; if it doesn’t appear, clear your browser’s cache.&lt;/p&gt;
&lt;h2&gt;
  
  
  6 README, License, and Git
&lt;/h2&gt;

&lt;p&gt;The README is the face of the project, so it’s important to pay attention to it. I delete the default contents. Here’s the structure I use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Project Name&lt;/span&gt;
badges (I’ll cover these in other articles)
description
&lt;span class="gu"&gt;## Screenshots&lt;/span&gt;
...
&lt;span class="gu"&gt;## How to Run (and Configure)&lt;/span&gt;
...
&lt;span class="gu"&gt;## How to Use&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a License.md file and copy the license text from &lt;a href="https://opensource.org/license/mit" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Note that you need to replace &lt;code&gt;&amp;lt;YEAR&amp;gt;&lt;/code&gt;and &lt;code&gt;&amp;lt;COPYRIGHT HOLDER&amp;gt;&lt;/code&gt; with the appropriate values.&lt;/p&gt;

&lt;p&gt;Our project template is now ready! Now let’s add it to Git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all for now. See you in the next post.&lt;/p&gt;

</description>
      <category>react</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>Swoole: an asynchronous framework for PHP</title>
      <dc:creator>Evgeniy Panov</dc:creator>
      <pubDate>Sat, 27 Dec 2025 19:08:39 +0000</pubDate>
      <link>https://dev.to/panov-eo/swoole-an-asynchronous-framework-for-php-21cc</link>
      <guid>https://dev.to/panov-eo/swoole-an-asynchronous-framework-for-php-21cc</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvh9skp5xskl01keqjdq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvh9skp5xskl01keqjdq.png" alt="Swoole - PHP on steroids" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Swoole is a high-performance extension for PHP that radically changes the approach to server application development. Unlike the classic PHP-FPM model, Swoole implements asynchronous I/O processing, uses coroutines, and provides built-in support for WebSocket and various network protocols.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation options
&lt;/h2&gt;

&lt;p&gt;Swoole is distributed through the &lt;a href="https://pecl.php.net/" rel="noopener noreferrer"&gt;PECL&lt;/a&gt; repository. To get started, you will need to install the basic components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;php php-dev php-pear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After completing the installation, you need to add the line &lt;code&gt;extension=openswoole.so&lt;/code&gt; to the php.ini configuration file.&lt;br&gt;
An alternative method is to use Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require openswoole/core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docker is suitable for an isolated development environment. You can use a ready-made PHP image with Swoole or create your own using Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM php:7.4-cli
RUN pecl install openswoole &amp;amp;&amp;amp; docker-php-ext-enable openswoole
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assembling and launching the container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t php-swoole .
docker run -p 9501:9501 -v $(pwd):/app -w /app php-swoole php your-script.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Swoole Architecture
&lt;/h2&gt;

&lt;p&gt;Swoole is built on a multi-process architecture with a clear separation of duties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The master&lt;/strong&gt; process coordinates the work of the entire system. It spawns reactor threads to handle networking, launches the process manager, and handles system signals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reactor threads&lt;/strong&gt; run inside the master process and manage network connections. Using &lt;code&gt;epoll&lt;/code&gt; or &lt;code&gt;kqueue&lt;/code&gt; mechanisms, they asynchronously receive data from clients and send it for processing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The process manager&lt;/strong&gt; monitors the lifecycle of worker processes, controls their status, and restarts them if necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workers&lt;/strong&gt; execute the main business logic of the application. They receive requests through reactor threads, process them, and generate responses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task Workers&lt;/strong&gt; are designed to perform heavy operations that can block the main thread: lengthy calculations, calls to external APIs, and other resource-intensive tasks.&lt;/p&gt;

&lt;p&gt;Request lifecycle:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A client request arrives at the main process's reactor thread&lt;/li&gt;
&lt;li&gt;The reactor thread passes the data to a worker process&lt;/li&gt;
&lt;li&gt;The worker process either handles the request itself or delegates tasks to task workers&lt;/li&gt;
&lt;li&gt;The result is returned to the client via the reactor thread&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Syntax basics
&lt;/h2&gt;

&lt;p&gt;Creating an HTTP server begins with initializing an instance of &lt;code&gt;OpenSwoole\HTTP\Server&lt;/code&gt;. Event handling is implemented through the &lt;code&gt;on&lt;/code&gt; method, and sending a response is implemented through the &lt;code&gt;end&lt;/code&gt; method of the Response object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\HTTP\Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9501&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello World&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Coroutines are used for asynchronous programming, which are launched by the &lt;code&gt;go&lt;/code&gt; or &lt;code&gt;co::run&lt;/code&gt; functions.&lt;br&gt;
WebSocket servers are configured similarly to HTTP servers with &lt;code&gt;open&lt;/code&gt;, &lt;code&gt;message&lt;/code&gt;, and &lt;code&gt;close&lt;/code&gt; event handling.&lt;br&gt;
The configuration of task processes looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'task_worker_num'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'task'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$taskId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// task processing logic&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'finish'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$taskId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$returnValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// actions after completion&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;TCP/UDP servers and clients&lt;br&gt;
The &lt;code&gt;OpenSwoole\Server&lt;/code&gt; class is used to create TCP/UDP servers. Parameters are configured using the &lt;code&gt;set&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9501&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'worker_num'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'receive'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$reactor_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Received: '&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fd&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;OpenSwoole\Coroutine\Client&lt;/code&gt; class is used for client connections, providing non-blocking network operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\Coroutine\Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;co&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SWOOLE_SOCK_TCP&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'127.0.0.1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9501&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Connection failed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;errCode&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello World&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;recv&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HTTP and WebSocket with coroutines
&lt;/h2&gt;

&lt;p&gt;An HTTP server is created using the &lt;code&gt;OpenSwoole\HTTP\Server&lt;/code&gt; class. Coroutines allow multiple requests to be processed in parallel without blocking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\HTTP\Server&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\Http\Response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"0.0.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9501&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Response&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello, Swoole HTTP!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The WebSocket server provides bidirectional communication via TCP. The &lt;code&gt;open&lt;/code&gt;, &lt;code&gt;message&lt;/code&gt;, and &lt;code&gt;close&lt;/code&gt; events allow you to control the entire connection lifecycle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\WebSocket\Server&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;OpenSwoole\WebSocket\Frame&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"0.0.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9502&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"open"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Server&lt;/span&gt; &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"New connection:  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Server&lt;/span&gt; &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Frame&lt;/span&gt; &lt;span class="nv"&gt;$frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Message received:  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$frame&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$frame&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"echo: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$frame&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"close"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$fd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Connection closed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$fd&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Practical examples
&lt;/h2&gt;

&lt;p&gt;A WebSocket server with routing and SSL support demonstrates Swoole's capabilities for creating secure real-time applications. Routing allows you to separate the logic for processing different types of requests, while SSL provides traffic encryption.&lt;br&gt;
An HTTP server with a routing system and validation shows how to implement a REST API with authentication and processing of various HTTP methods.&lt;br&gt;
Detailed documentation and additional examples are available on the &lt;a href="https://www.php.net/manual/ru/book.swoole.php" rel="noopener noreferrer"&gt;official project website&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>php</category>
    </item>
  </channel>
</rss>
