TCP

The RoadRunner TCP plugin helps you handle TCP requests. You can use this plugin to make your own servers like an SMTP server, and send TCP requests directly to PHP workers for handling.

Principle of work

The RoadRunner TCP plugin operates by receiving client requests and proxying them to free PHP workers that are not currently processing any request.

The request sent to the PHP worker contains the following context:

  • event - The event type. The following events are supported:

    • CONNECTED: Sent when a client connects to the server.

    • DATA: Sent when a client sends data to the server.

    • CLOSED: Sent when a client disconnects from the server.

  • remote_addr: The client's IP address.

  • server: The server name, as specified in the RoadRunner configuration (e.g., smtp, server2).

  • body: The request body.

  • uuid: The connection UUID.

The protocol used by the RoadRunner TCP plugin provides a bidirectional communication channel between the PHP worker and the RoadRunner server. This design allows PHP workers to send responses back to the client, enabling seamless handling of client requests and communication between all parties.

Configuration

The TCP plugin is configured via the tcp section of the RoadRunner configuration file.

Here is an example configuration:

You can define command to start server in the server.command section:. It will be used to start PHP workers for all registered plugins, such as grpc, http, jobs, etc.

Configuration Parameters

  • servers: A list of TCP servers to start. Each server should contain the following keys:

    • addr: The server address and port, specified in the format tcp://<IP_ADDRESS>:<PORT>.

    • delimiter: (Optional) The data packet delimiter. By default, it is set to \r. Each data packet should end either with an EOF or the specified delimiter.

  • pool: Configuration for the PHP worker pool for the TCP servers. See https://docs.roadrunner.dev/docs/php-worker/pool for available parameters.

PHP client

The RoadRunner TCP plugin comes with a convenient PHP package that simplifies the process of integrating the plugin with your PHP application.

Installation

To get started, you can install the package via Composer using the following command:

Usage

The following example demonstrates how to create a simple PHP worker:

What's Next?

  1. Plugins β€” KV - Learn how to use the Key Value plugin to store data between requests.

Last updated

Was this helpful?