Backend Development 4 min read

Getting Started with Workerman: Installation, Commands, and RPC Usage in PHP

This guide introduces the high‑performance Workerman PHP socket framework, outlines its key features, provides step‑by‑step installation and start/stop commands, and demonstrates how to build and consume RPC services with both synchronous and asynchronous client calls.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Getting Started with Workerman: Installation, Commands, and RPC Usage in PHP

Workerman is a high‑performance PHP socket service framework that enables developers to build various network applications such as RPC services, chat rooms, and games.

Key features include multi‑process support, TCP/UDP handling, various application‑layer protocols, libevent‑based event loop for high concurrency, file change detection, smooth worker reload, telnet control, exception monitoring, long‑connection support, and the ability to run workers under specific users.

Installation

1. Download or clone the repository:

https://github.com/walkor/workerman-JsonRpc

2. Install dependencies:

composer install

Start / Stop Commands

php start.php start -d
php start.php restart
php start.php reload
php start.php status
php start.php stop

RPC Application Usage

Server side : Service classes are placed in Applications/JsonRpc/Services . Example class User.php provides static methods such as getInfoByUid and getEmail .

<?php
class User {
    public static function getInfoByUid($uid) {
        // ....
    }
    public static function getEmail($uid) {
        // ...
    }
}

Client synchronous call :

<?php
include_once 'yourClientDir/RpcClient.php';
$address_array = array('tcp://127.0.0.1:2015','tcp://127.0.0.1:2015');
RpcClient::config($address_array);
$uid = 567;
$user_client = RpcClient::instance('User');
$ret_sync = $user_client->getInfoByUid($uid);

Client asynchronous call :

<?php
include_once 'yourClientDir/RpcClient.php';
$address_array = array('tcp://127.0.0.1:2015','tcp://127.0.0.1:2015');
RpcClient::config($address_array);
$uid = 567;
$user_client = RpcClient::instance('User');
$user_client->asend_getInfoByUid($uid);
$user_client->asend_getEmail($uid);
// other business logic …
$ret_async1 = $user_client->arecv_getEmail($uid);
$ret_async2 = $user_client->arecv_getInfoByUid($uid);

Monitoring page is available at http:// ip :55757 .

backendRPCphphigh performancesocketWorkerman
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.