# 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
没有合适的资源?快使用搜索试试~ 我知道了~
聊天网站源码 H5聊天系统源码 支持自助建群 无限创群 管理群.zip
共1440个文件
php:310个
png:253个
jpeg:233个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 111 浏览量
2023-12-23
10:11:14
上传
评论
收藏 49MB ZIP 举报
温馨提示
H5聊天系统聊天网站源码 群聊源码 无限建群创群 1.支持自助建群 管理群 修改群资料 2.支持自动登录 登陆成功可自助修改资料 3.后台可查看群组聊天消息记录 4.支持表情 动态表情 图片发布 5.支持消息语音提醒 测试环境:Nginx+MySQL5.6+PHP5.6 1.将压缩包解压到网站:根目录 2.设置网站/public为运行目录 3.将伪静态设置为:tinkphp 4.新建数据库—导入数据库.sql 5.修改配置文件 /application/database.php 管理后台:域名/ljc 账号密码:admin/123456
资源推荐
资源详情
资源评论
收起资源包目录
聊天网站源码 H5聊天系统源码 支持自助建群 无限创群 管理群.zip (1440个子文件)
& 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
addfd.html.bak 6KB
listgroup.html.bak 6KB
addgroup.html.bak 6KB
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
Index.php.bak 537B
test.bmp 0B
main.css 787KB
style.css 99KB
style.css 60KB
dashicons.css 56KB
weui.css 50KB
layout.css 43KB
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
layout.csss 40KB
reset.csss 8KB
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
7.gif 92KB
4.gif 91KB
共 1440 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
智慧浩海
- 粉丝: 1w+
- 资源: 5459
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 1Cr18Ni9Ti钢板焊接接头冷弯开裂的试验研究.pdf
- 1Cr18Ni9Ti钎焊接头组织和性能影响研究 - .pdf
- 2.25 Cr-1 Mo钢制加氢反应器的焊接裂纹(二)-对焊接裂纹性质的试验研究.pdf
- 1Crl8Ni9Ti不锈钢复合管系的焊接 - .pdf
- 2.25Cr-1Mo-0.25V低合金钢用焊接材料的检验 - .pdf
- 2.25-1Mo钢焊后产生焊接裂纹的原因分析及其返修措施.pdf
- 2.25 Cr-1 Mo钢制加氢反应器的焊接裂纹(一)-在制过程中出现的焊接裂纹.pdf
- 2.25Cr-1Mo-0.25V钢焊接材料的再热裂纹敏感性试验方法探讨.pdf
- 2A12厚板铝合金搅拌摩擦焊接头组织性能研究 - .pdf
- 2万立立式液氢高压容器的焊接研制.pdf
- 2A14铝合金法兰焊接裂纹修复.pdf
- 3.5%Ni钢焊接接头的低温韧性研究三──熔敷金属碳含量等因素的影响.pdf
- 3.5%Ni钢焊接技术的最近进展.pdf
- 3.5%Ni钢焊接接头低温韧性的研究二──焊后热处理母材及焊材的影响.pdf
- 3.5%Ni钢焊接接头低温韧性的研究一──线能量层间温度的影响.pdf
- 3.5Ni钢低温设备的制造和焊接.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功