
Workerman is an open source high-performance asynchronous PHP socket instant messaging framework. Supports high concurrency and ultra-high stability, and is widely used in mobile apps, mobile communications, WeChat applets, mobile game servers, online games, PHP chat rooms, hardware communications, smart homes, Internet of Vehicles, Internet of Things and other fields. development. (Recommended learning: workerman tutorial)
Supports TCP long connections, supports Websocket, HTTP and other protocols, and supports custom protocols. It has many high-performance components such as asynchronous Mysql, asynchronous Redis, asynchronous Http, MQTT IoT client, asynchronous message queue, etc.
workerman itself is a PHP multi-process server framework with modules for PHP process management and socket communication, so it can run independently without relying on containers such as php-fpm, nginx or apache.
1. First download the official Workerman framework
2.As a server side
in workererman Create a new file in the framework root directory
use Workerman\Worker;
require_once __DIR__ . '/Workerman/Autoloader.php';
// 注意:使用的是websocket协议
$ws_worker = new Worker("websocket://0.0.0.0:2000"); //这里最好是0.0.0.0
// 启动4个进程对外提供服务
$ws_worker->count = 4;
$ws_worker->onWorkerStart = function($ws_worker){
};
$ws_worker->onConnect = function($ws_worker){
};
$ws_worker->onMessage = function($connection, $data)use($ws_worker){ //如果想用$ws_worker的话需要 use传进来
};
$worker->onClose = function($connection){
};
php yaofile.php start debug模式 启动
php yaofile.php start -d (守护进程)启动3. Front-end code
ws = new WebSocket("ws://47.90.81.150:2000"); //服务器的ip
ws.onopen = function() {
console.log("连接成功");
}
ws.onmessage = function(e) {
console.log("收到服务端的消息:" + e.data);
}
foreach($ws_worker->connections as $connection) {
$connection->send($cachearray);
}4.As a client
use Workerman\Connection\AsyncTcpConnection; //要引用这个文件
$con = new AsyncTcpConnection('ws://api.huobi.pro:443/ws'); //远程服务器的连接
// 设置以ssl加密方式访问,使之成为wss
$con->transport = 'ssl';
$con->onConnect = function($con) {
$con->send($data);
}
$con->onMessage = function($con, $data) {
};
$con->connect();The above is the detailed content of How to use workerman. For more information, please follow other related articles on the PHP Chinese website!
What Are the Key Features of Workerman's Built-in WebSocket Client?Mar 18, 2025 pm 04:20 PMWorkerman's WebSocket client enhances real-time communication with features like asynchronous communication, high performance, scalability, and security, easily integrating with existing systems.
How to Use Workerman for Building Real-Time Collaboration Tools?Mar 18, 2025 pm 04:15 PMThe article discusses using Workerman, a high-performance PHP server, to build real-time collaboration tools. It covers installation, server setup, real-time feature implementation, and integration with existing systems, emphasizing Workerman's key f
What Are the Best Ways to Optimize Workerman for Low-Latency Applications?Mar 18, 2025 pm 04:14 PMThe article discusses optimizing Workerman for low-latency applications, focusing on asynchronous programming, network configuration, resource management, data transfer minimization, load balancing, and regular updates.
How to Implement Real-Time Data Synchronization with Workerman and MySQL?Mar 18, 2025 pm 04:13 PMThe article discusses implementing real-time data synchronization using Workerman and MySQL, focusing on setup, best practices, ensuring data consistency, and addressing common challenges.
What Are the Key Considerations for Using Workerman in a Serverless Architecture?Mar 18, 2025 pm 04:12 PMThe article discusses integrating Workerman into serverless architectures, focusing on scalability, statelessness, cold starts, resource management, and integration complexity. Workerman enhances performance through high concurrency, reduced cold sta
How to Build a High-Performance E-Commerce Platform with Workerman?Mar 18, 2025 pm 04:11 PMThe article discusses building a high-performance e-commerce platform using Workerman, focusing on its features like WebSocket support and scalability to enhance real-time interactions and efficiency.
What Are the Advanced Features of Workerman's WebSocket Server?Mar 18, 2025 pm 04:08 PMWorkerman's WebSocket server enhances real-time communication with features like scalability, low latency, and security measures against common threats.
How to Use Workerman for Building Real-Time Analytics Dashboards?Mar 18, 2025 pm 04:07 PMThe article discusses using Workerman, a high-performance PHP server, to build real-time analytics dashboards. It covers installation, server setup, data processing, and frontend integration with frameworks like React, Vue.js, and Angular. Key featur


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software






