# Workerman
## What is it
Workerman is a library for event-driven programming in PHP. It has a huge number of features. Each worker is able to handle thousands of connections.
## 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
test.php
```php
<?php
use Workerman\Worker;
require_once './Workerman/Autoloader.php';
// 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();
```
### A http server
test.php
```php
require_once './Workerman/Autoloader.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
test.php
```php
require_once './Workerman/Autoloader.php';
use \Workerman\WebServer;
// 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
test.php
```php
require_once './Workerman/Autoloader.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($connection)
{
echo "Connection closed\n";
};
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";
}
}
```
test.php
```php
require_once './Workerman/Autoloader.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
test.php
```php
require_once './Workerman/Autoloader.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();
```
run width
```php test.php start```
## Available commands
```php test.php start ```
```php test.php start -d ```
![workerman start](http://www.workerman.net/img/workerman-start.png)
```php test.php status ```
![workerman satus](http://www.workerman.net/img/workerman-status.png?a=123)
```php test.php stop ```
```php test.php restart ```
```php test.php reload ```
## Documentation
中文主页:[http://www.workerman.net](http://www.workerman.net)
中文文档: [http://doc3.workerman.net](http://doc3.workerman.net)
Documentation:[https://github.com/walkor/workerman-manual](https://github.com/walkor/workerman-manual/blob/master/english/src/SUMMARY.md)
# Benchmarks
```
CPU: Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz and 4 processors totally
Memory: 8G
OS: Ubuntu 14.04 LTS
Software: ab
PHP: 5.5.9
```
**Codes**
```php
<?php
use Workerman\Worker;
$worker = new Worker('tcp://0.0.0.0:1234');
$worker->count=3;
$worker->onMessage = function($connection, $data)
{
$connection->send("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nServer: workerman\1.1.4\r\n\r\nhello");
};
Worker::runAll();
```
**Result**
```shell
ab -n1000000 -c100 -k http://127.0.0.1:1234/
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests
Server Software: workerman/3.1.4
Server Hostname: 127.0.0.1
Server Port: 1234
Document Path: /
Document Length: 5 bytes
Concurrency Level: 100
Time taken for tests: 7.240 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 73000000 bytes
HTML transferred: 5000000 bytes
Requests per second: 138124.14 [#/sec] (mean)
Time per request: 0.724 [ms] (mean)
Time per request: 0.007 [ms] (mean, across all concurrent requests)
Transfer rate: 9846.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 5
Processing: 0 1 0.2 1 9
Waiting: 0 1 0.2 1 9
Total: 0 1 0.2 1 9
Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 1
95% 1
98% 1
99% 1
100% 9 (longest request)
```
# Demos
## [tadpole](http://kedou.workerman.net/)
[Live demo](http://kedou.workerman.net/)
[Source code](https://github.com/walkor/workerman)
![workerman todpole](http://www.workerman.net/img/workerman-todpole.png)
## [BrowserQuest](http://www.workerman.net/demos/browserquest/)
[Live demo](http://www.workerman.net/demos/browserquest/)
[Source code](https://github.com/walkor/BrowserQuest-PHP)
![BrowserQuest width workerman](http://www.workerman.net/img/browserquest.jpg)
## [web vmstat](http://www.workerman.net/demos/vmstat/)
[Live demo](http://www.workerman.net/demos/vmstat/)
[Source code](https://github.com/walkor/workerman-vmstat)
![web vmstat](http://www.workerman.net/img/workerman-vmstat.png)
## [live-ascii-camera](https://github.com/walkor/live-ascii-camera)
[Live demo camera page](http://www.workerman.net/demos/live-ascii-camera/camera.html)
[Live demo receive page](http://www.workerman.net/dem
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码-小微开源PHPOA办公系统源码.zip
共536个文件
html:255个
php:177个
dll:52个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 155 浏览量
2022-10-17
05:04:06
上传
评论 1
收藏 14.01MB ZIP 举报
温馨提示
PHP实例开发源码—小微开源PHPOA办公系统源码.zip PHP实例开发源码—小微开源PHPOA办公系统源码.zip PHP实例开发源码—小微开源PHPOA办公系统源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码-小微开源PHPOA办公系统源码.zip (536个子文件)
main.css.bak 11KB
start.php.bak 4KB
start.bat 74B
phar.phar.bat 38B
openssl.cnf 9KB
main.css 11KB
main.css 6KB
style.css 2KB
icudt49.dll 17.13MB
php_fileinfo.dll 2.56MB
icuin49.dll 1.61MB
php_gd2.dll 1.49MB
glib-2.dll 1.31MB
icuuc49.dll 1.23MB
php_mbstring.dll 1.15MB
libeay32.dll 997KB
php_imap.dll 796KB
php_sqlite3.dll 697KB
php_pdo_sqlite.dll 507KB
php_curl.dll 368KB
php_snmp.dll 310KB
libenchant_myspell.dll 287KB
php_soap.dll 242KB
php_gmp.dll 221KB
php_tidy.dll 221KB
php_xsl.dll 215KB
icule49.dll 192KB
libssh2.dll 163KB
php_ldap.dll 158KB
icutu49.dll 144KB
php_oci8_11g.dll 142KB
php_oci8.dll 141KB
php_intl.dll 137KB
libpq.dll 96KB
php_pgsql.dll 95KB
php_mysqli.dll 89KB
php_openssl.dll 72KB
php_com_dotnet.dll 70KB
libsasl.dll 67KB
php_interbase.dll 63KB
php_bz2.dll 59KB
php_xmlrpc.dll 57KB
icutest49.dll 55KB
icuio49.dll 46KB
libenchant_ispell.dll 44KB
iculx49.dll 43KB
php_exif.dll 43KB
libenchant.dll 42KB
php_sockets.dll 40KB
php_gettext.dll 39KB
php_mysql.dll 35KB
php_sybase_ct.dll 31KB
php_pdo_pgsql.dll 27KB
php_pdo_mysql.dll 24KB
php_pdo_oci.dll 24KB
php_pdo_firebird.dll 21KB
php_pdo_odbc.dll 21KB
php_enchant.dll 19KB
gmodule-2.dll 16KB
php_shmop.dll 12KB
deplister.exe 47KB
php-cgi.exe 7KB
.gitattributes 483B
.gitattributes 483B
.gitignore 56B
.gitignore 56B
index.html 16KB
index.html 16KB
day_view.html 15KB
day_view.html 15KB
read.html 13KB
read.html 11KB
flow.html 10KB
index.html 10KB
index.html 9KB
emp.html 9KB
reply.html 8KB
index.html 8KB
add.html 8KB
index.html 8KB
read.html 8KB
read.html 8KB
index.html 8KB
edit.html 8KB
folder.html 8KB
index.html 8KB
edit.html 8KB
contact.html 8KB
index.html 8KB
add.html 7KB
index.html 7KB
confirm.html 7KB
edit.html 7KB
index.html 7KB
scope.html 6KB
index.html 6KB
task.html 6KB
auth.html 6KB
work_order.html 6KB
folder.html 6KB
共 536 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
易小侠
- 粉丝: 6442
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于 LSTM(长短期记忆)(即改进的循环神经网络)预测风力发电厂中风力涡轮机产生的功率+源代码+文档说明
- 基于stm32f103+空心杯电机+oled按键+运动算法
- 《CKA/CKAD应试指南/从docker到kubernetes 完全攻略》学习笔记 第1章docker基础(1.1-1.4)
- 基于python实现的水下压缩空气储能互补系统建模仿真与经济效益分析+源代码+论文
- 华中科技大学-自然语言处理实验,Bi-LSTM+CRF的中文分词框架,并且利用基于深度学习的方法进行中文命名实体识别++源码报告
- 基于动态罚函数的铁路车流分配与径路优化模型python源码
- 鱼群算法求解组环问题python源码+文档说明
- 基于决策优化的多波束测深测线规划模型MATLAB代码
- 课程设计-基于python实现的多目标优化算法求解带时间窗的车辆路径规划问题+源代码+文档说明+界面截图+pptx
- 基于通信信号与通信系统的MATLAB仿真源码-课程设计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功