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.
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-JsonRpc2. Install dependencies:
composer installStart / Stop Commands
php start.php start -d
php start.php restart
php start.php reload
php start.php status
php start.php stopRPC 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 .
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.