# 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
没有合适的资源?快使用搜索试试~ 我知道了~
随便撸手机悬赏任务赚钱 自动挂机阅读文章app源码
共1933个文件
php:389个
gif:350个
js:301个
1星 需积分: 41 33 下载量 199 浏览量
2019-05-28
18:01:11
上传
评论 16
收藏 26.15MB RAR 举报
温馨提示
说明文档:https://www.suibianlu.com/14185.html; 源码描述: 手机悬赏任务赚钱源码+自动挂机阅读文章源码 源码介绍: 全网独家挂机阅读文章赚钱,首页还有悬赏任务,悬赏任务对接了任务联盟,并且也支持后台单独上传任务,至于怎么赚钱,查看演示站下载app即可明白。 悬赏任务+自动挂机阅读文章+徒弟功能以及其他很多的丰富功能,具体查看演示站吧。 悬赏任务可以后台自主上传,并且后台还对接的有任务联盟,如果自己上传的任务不够多,也可以通过任务联盟来补充,任务联盟的收入你都有分成。 挂机里面的广告是通过在后台设置链接来投放,链接没有限制,可以自己接广告联盟的或者有广告商找到你投放。 挂机这块用户分为4个等级,普通用户区建议设置金额低点,挂机时间长一点。其他vip会员区都是需要付费给你才能开通的。 所有任务均可以设置挂机时间以及金额,比如你可以设置某个区1分钟获取1毛,或者10分钟获取1毛。 后台对接了码支付平台。 目前本平台正在运营,全网独家,所以买了之后直接就可以赚钱。
资源推荐
资源详情
资源评论
收起资源包目录
随便撸手机悬赏任务赚钱 自动挂机阅读文章app源码 (1933个子文件)
milizhuan.apk 1.93MB
jquery.js.bak 69KB
jquery.js.bak 69KB
admin.js.bak 25KB
index.html.bak 25KB
viesite.html.bak 23KB
ueditor.config.js.bak 22KB
index.html.bak 18KB
index.html.bak 17KB
index.html.bak 17KB
userlist.html.bak 15KB
User.php.bak 15KB
index.html.bak 14KB
index.html.bak 13KB
info.html.bak 13KB
tixian.html.bak 13KB
Pro.php.bak 12KB
index.html.bak 11KB
payorder.html.bak 10KB
index.html.bak 10KB
index.html.bak 10KB
index.html.bak 10KB
Clist.php.bak 10KB
index.html.bak 10KB
yaoqing.html.bak 9KB
config.php.bak 9KB
form.js.bak 9KB
usermo.html.bak 9KB
listform.html.bak 9KB
register.html.bak 8KB
index.html.bak 8KB
index.html.bak 8KB
userinfo.html.bak 8KB
vip.html.bak 7KB
tixian.html.bak 7KB
layui.js.bak 7KB
qianbao.html.bak 6KB
index.html.bak 6KB
Pay.php.bak 6KB
config.json.bak 6KB
index.html.bak 6KB
Index.php.bak 6KB
textlist.html.bak 5KB
jilu.html.bak 5KB
reg.html.bak 5KB
index.html.bak 5KB
login.html.bak 5KB
pay.html.bak 5KB
Login.php.bak 5KB
Gua.php.bak 4KB
yaoinfo.html.bak 4KB
yaocode.html.bak 4KB
guanyu.html.bak 4KB
listform.html.bak 4KB
listform.html.bak 4KB
Gua.php.bak 3KB
listform.html.bak 3KB
console.html.bak 3KB
fo.html.bak 3KB
base.php.bak 3KB
help.html.bak 3KB
listform.html.bak 3KB
remsg.html.bak 2KB
listform.html.bak 2KB
listform.html.bak 2KB
about.html.bak 2KB
Ucenter.php.bak 1KB
index.php.bak 830B
Common.php.bak 752B
common.php.bak 682B
Text.php.bak 248B
public.js.bak 240B
.htaccess.bak 224B
public.css.bak 122B
test.bmp 0B
layui.css 68KB
layui.css 68KB
layui.css 68KB
layui.css 68KB
index.css 60KB
index.css 60KB
simplepro.css 48KB
simplepro.css 48KB
ueditor.css 44KB
ueditor.min.css 34KB
reg.css 30KB
info.css 26KB
info.css 26KB
admin.css 26KB
admin.css 26KB
uni.css 25KB
uni.css 25KB
video-js.css 21KB
image.css 19KB
layim.css 15KB
layim.css 15KB
video.css 15KB
attachment.css 15KB
layer.css 14KB
layer.css 14KB
共 1933 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- 浅蓝色的微笑2020-05-21这都卖这多积分,我也进坑了
- 祈青思2019-08-17不好,别下,浪费时间,加密的,很多地方要授权
- qq_433004262019-12-03基本不能用,进都进不去
phubing
- 粉丝: 607
- 资源: 850
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功