# Workerman
[![Gitter](https://badges.gitter.im/walkor/Workerman.svg)](https://gitter.im/walkor/Workerman?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge)
[![Latest Stable Version](https://poser.pugx.org/workerman/workerman/v/stable)](https://packagist.org/packages/workerman/workerman)
[![Total Downloads](https://poser.pugx.org/workerman/workerman/downloads)](https://packagist.org/packages/workerman/workerman)
[![Monthly Downloads](https://poser.pugx.org/workerman/workerman/d/monthly)](https://packagist.org/packages/workerman/workerman)
[![Daily Downloads](https://poser.pugx.org/workerman/workerman/d/daily)](https://packagist.org/packages/workerman/workerman)
[![License](https://poser.pugx.org/workerman/workerman/license)](https://packagist.org/packages/workerman/workerman)
## What is it
Workerman is an asynchronous event driven PHP framework with high performance for easily building fast, scalable network applications. Supports HTTP, Websocket, SSL and other custom protocols. Supports libevent, [HHVM](https://github.com/facebook/hhvm) , [ReactPHP](https://github.com/reactphp/react).
## Requires
PHP 5.3 or Higher
A POSIX compatible operating system (Linux, OSX, BSD)
POSIX and PCNTL extensions for PHP
## Installation
```
composer require workerman/workerman
```
## Basic Usage
### A websocket server
```php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// Create a Websocket server
$ws_worker = new Worker("websocket://0.0.0.0:2346");
// 4 processes
$ws_worker->count = 4;
// Emitted when new connection come
$ws_worker->onConnect = function($connection)
{
echo "New connection\n";
};
// Emitted when data received
$ws_worker->onMessage = function($connection, $data)
{
// Send hello $data
$connection->send('hello ' . $data);
};
// Emitted when connection closed
$ws_worker->onClose = function($connection)
{
echo "Connection closed\n";
};
// Run worker
Worker::runAll();
```
### An http server
```php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// #### http worker ####
$http_worker = new Worker("http://0.0.0.0:2345");
// 4 processes
$http_worker->count = 4;
// Emitted when data received
$http_worker->onMessage = function($connection, $data)
{
// $_GET, $_POST, $_COOKIE, $_SESSION, $_SERVER, $_FILES are available
var_dump($_GET, $_POST, $_COOKIE, $_SESSION, $_SERVER, $_FILES);
// send data to client
$connection->send("hello world \n");
};
// run all workers
Worker::runAll();
```
### A WebServer
```php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\WebServer;
use Workerman\Worker;
// WebServer
$web = new WebServer("http://0.0.0.0:80");
// 4 processes
$web->count = 4;
// Set the root of domains
$web->addRoot('www.your_domain.com', '/your/path/Web');
$web->addRoot('www.another_domain.com', '/another/path/Web');
// run all workers
Worker::runAll();
```
### A tcp server
```php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// #### create socket and listen 1234 port ####
$tcp_worker = new Worker("tcp://0.0.0.0:1234");
// 4 processes
$tcp_worker->count = 4;
// Emitted when new connection come
$tcp_worker->onConnect = function($connection)
{
echo "New Connection\n";
};
// Emitted when data received
$tcp_worker->onMessage = function($connection, $data)
{
// send data to client
$connection->send("hello $data \n");
};
// Emitted when new connection come
$tcp_worker->onClose = function($connection)
{
echo "Connection closed\n";
};
Worker::runAll();
```
### Enable SSL
```php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// SSL context.
$context = array(
'ssl' => array(
'local_cert' => '/your/path/of/server.pem',
'local_pk' => '/your/path/of/server.key',
'verify_peer' => false,
)
);
// Create a Websocket server with ssl context.
$ws_worker = new Worker("websocket://0.0.0.0:2346", $context);
// Enable SSL. WebSocket+SSL means that Secure WebSocket (wss://).
// The similar approaches for Https etc.
$ws_worker->transport = 'ssl';
$ws_worker->onMessage = function($connection, $data)
{
// Send hello $data
$connection->send('hello ' . $data);
};
Worker::runAll();
```
### Custom protocol
Protocols/MyTextProtocol.php
```php
namespace Protocols;
/**
* User defined protocol
* Format Text+"\n"
*/
class MyTextProtocol
{
public static function input($recv_buffer)
{
// Find the position of the first occurrence of "\n"
$pos = strpos($recv_buffer, "\n");
// Not a complete package. Return 0 because the length of package can not be calculated
if($pos === false)
{
return 0;
}
// Return length of the package
return $pos+1;
}
public static function decode($recv_buffer)
{
return trim($recv_buffer);
}
public static function encode($data)
{
return $data."\n";
}
}
```
```php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// #### MyTextProtocol worker ####
$text_worker = new Worker("MyTextProtocol://0.0.0.0:5678");
$text_worker->onConnect = function($connection)
{
echo "New connection\n";
};
$text_worker->onMessage = function($connection, $data)
{
// send data to client
$connection->send("hello world \n");
};
$text_worker->onClose = function($connection)
{
echo "Connection closed\n";
};
// run all workers
Worker::runAll();
```
### Timer
```php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Lib\Timer;
$task = new Worker();
$task->onWorkerStart = function($task)
{
// 2.5 seconds
$time_interval = 2.5;
$timer_id = Timer::add($time_interval,
function()
{
echo "Timer run\n";
}
);
};
// run all workers
Worker::runAll();
```
### AsyncTcpConnection (tcp/ws/text/frame etc...)
```php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Connection\AsyncTcpConnection;
$worker = new Worker();
$worker->onWorkerStart = function()
{
// Websocket protocol for client.
$ws_connection = new AsyncTcpConnection("ws://echo.websocket.org:80");
$ws_connection->onConnect = function($connection){
$connection->send('hello');
};
$ws_connection->onMessage = function($connection, $data){
echo "recv: $data\n";
};
$ws_connection->onError = function($connection, $code, $msg){
echo "error: $msg\n";
};
$ws_connection->onClose = function($connection){
echo "connection closed\n";
};
$ws_connection->connect();
};
Worker::runAll();
```
### Async Mysql of ReactPHP
```
composer require react/mysql
```
```php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
$worker = new Worker('tcp://0.0.0.0:6161');
$worker->onWorkerStart = function() {
global $mysql;
$loop = Worker::getEventLoop();
$mysql = new React\MySQL\Connection($loop, array(
'host' => '127.0.0.1',
'dbname' => 'dbname',
'user' => 'user',
'passwd' => 'passwd',
));
$mysql->on('error', function($e){
echo $e;
});
$mysql->connect(function ($e) {
if($e) {
echo $e;
} else {
echo "connect success\n";
}
});
};
$worker->onMessage = function($connection, $data) {
global $mysql;
$mysql->query('show databases' /*trim($data)*/, function ($command, $mysql) use ($connection) {
if ($command->hasError()) {
$error = $command->getError();
} else {
$results = $command->resultRows;
$fields = $command->resultFields;
$connection->send(json_encode($results));
}
});
};
Worker::runAll();
```
### Async Redis of ReactPHP
```
composer require clue/redis-react
```
```php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Clu
没有合适的资源?快使用搜索试试~ 我知道了~
THINKPHP聊天软件H5实时聊天室自动分配账户全开源商业源码
共1480个文件
php:292个
png:252个
jpeg:229个
需积分: 3 4 下载量 3 浏览量
2023-03-23
10:44:55
上传
评论
收藏 47.52MB ZIP 举报
温馨提示
源码引见 THINKPHP聊天软件H5实时聊天室,自动分配账户,全开源商业源码 都是去年买的,很多买的源码根本都下架了, 不过还是不影响这个源码的牛逼所在 运营版本的聊天室,能够添加好友,树立群组,私聊,禁言功用 H5+TP5.0+mysql+PHP 源码开源不加密
资源推荐
资源详情
资源评论
收起资源包目录
THINKPHP聊天软件H5实时聊天室自动分配账户全开源商业源码 (1480个子文件)
& 0B
compactcard.html.bak 35KB
usercenter.html.bak 34KB
groupchat.js.bak 13KB
settings.html.bak 12KB
Index.php.bak 12KB
userinfo.html.bak 11KB
groupchat.html.bak 8KB
fdchat.html.bak 8KB
top.html.bak 8KB
leftlist.html.bak 7KB
addfd.html.bak 6KB
listgroup.html.bak 6KB
addgroup.html.bak 6KB
Index.php.bak 5KB
Index.php.bak 4KB
reg.html.bak 4KB
adminlogin.html.bak 4KB
login.html.bak 4KB
Index.php.bak 3KB
Index.php.bak 3KB
Base.php.bak 2KB
test.bmp 0B
main.css 787KB
style.css 99KB
style.css 60KB
dashicons.css 56KB
weui.css 50KB
layout.css 40KB
font-awesome.min.css 30KB
weather-icons.min.css 26KB
typicons.css 22KB
style.css 22KB
style.css 21KB
foundation-icons.css 19KB
style.css 19KB
swiper-3.4.1.min.css 17KB
themify-icons.css 16KB
fullcalendar.min.css 15KB
select2.min.css 15KB
simple-line-icons.css 13KB
dropzone.css 12KB
default-skin.css 11KB
webfont.css 11KB
style.css 10KB
wcPop.css 9KB
reset.css 8KB
daterangepicker.css 8KB
style.css 6KB
perfect-scrollbar.min.css 4KB
dataTables.bootstrap.min.css 4KB
photoswipe.css 4KB
animate.css 4KB
ion.rangeSlider.css 3KB
commes.css 2KB
slick.css 2KB
dragula.min.css 466B
Migration.template.php.dist 756B
Seed.template.php.dist 326B
fontawesome-webfont.eot 162KB
typicons.eot 98KB
weathericons-regular-webfont.eot 97KB
themify.eot 77KB
entypo.eot 69KB
Metrize-Icons.eot 62KB
dashicons.eot 53KB
foundation-icons.eot 53KB
Simple-Line-Icons.eot 53KB
dripicons-v2.eot 40KB
eightyshades.eot 13KB
hiddeninput.exe 9KB
test.gif 233KB
8.gif 147KB
3.gif 131KB
12.gif 129KB
13.gif 127KB
0.gif 127KB
11.gif 120KB
4.gif 119KB
face-lbl.gif 119KB
9.gif 115KB
1.gif 115KB
11.gif 115KB
2.gif 99KB
14.gif 98KB
6.gif 98KB
2.gif 98KB
9.gif 97KB
4.gif 97KB
12.gif 97KB
10.gif 97KB
8.gif 97KB
11.gif 97KB
13.gif 97KB
3.gif 95KB
5.gif 95KB
13.gif 94KB
face-lbl.gif 94KB
15.gif 94KB
11.gif 92KB
共 1480 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
普通网友
- 粉丝: 4733
- 资源: 910
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- postman1111
- 快递盒打包机sw18可编辑全套技术资料100%好用.zip
- 画流程图程序的资源包,下载后npm执行就可以
- 基于OOD、JAVA和SWING的足球联赛管理系统软件的设计与实现
- 冷却收卷生产线(sw18可编辑+工程图+bom)全套技术资料100%好用.zip
- 雷达主板测试设备sw19可编辑全套技术资料100%好用.zip
- 龙门桁架sw18可编辑全套技术资料100%好用.zip
- 流水线贴标机sw18全套技术资料100%好用.zip
- 链式传输带sw18可编辑全套技术资料100%好用.zip
- CrystalDiskInfo可检测固态硬盘NAND写入量
- 龙门架双机械手sw18可编辑全套技术资料100%好用.zip
- SSD系列X2.zipSSD系列X2.zip
- 闪迪SSD管理工具Dashboard-V2.3.1.0.zip
- 龙门架快递搬运机器人sw18全套技术资料100%好用.zip
- 闪迪SSD工具Dashboard-v3.2.2.9.zip
- 计算机网络实验报告:使用Wireshark嗅探来自两个HTTP网站的数据包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功