swoole在线聊天学习笔记
<?php
$http=new swoole_http_server('0.0.0.0',); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
print_r($request);
}); $http->start();

http://192.168.10.31:9501/swoole/chat/chat/http_server.php




<?php
$http=new swoole_http_server('0.0.0.0',); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
$response->end("hello world");
}); $http->start();


<?php
$http=new swoole_http_server('0.0.0.0',); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
//$response->end("hello world");
$response->status(404);
$response->end('404 not found');
}); $http->start();


<?php
$http=new swoole_http_server('0.0.0.0',); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
//$response->end("hello world");
//$response->status(404);
//$response->end('404 not found');
$pathinfo=$request->server['path_info'];
$in=strrpos($pathinfo,'/');
$filename=substr($pathinfo,$in);
$filename=__DIR__.$pathinfo;
if(is_file($filename)){
$content=file_get_contents($filename);
$response->end($content);
}else{
$response->status(404);
$response->end('404 not found');
}
}); $http->start();




<?php
$http=new swoole_http_server('0.0.0.0',); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
//$response->end("hello world");
//$response->status(404);
//$response->end('404 not found');
$pathinfo=$request->server['path_info'];
$in=strrpos($pathinfo,'/');
$filename=substr($pathinfo,$in);
$filename=__DIR__.$filename;
if(is_file($filename)){
$ext=pathinfo($request->server['path_info'],PATHINFO_EXTENSION);
//动态请求处理
if($ext=='php'){
ob_start();
include_once $filename;
$content=ob_get_contents();
ob_end_clean();
$response->end($content);
}else{ //静态请求处理
$content=file_get_contents($filename);
$response->end($content);
}
}else{
$response->status();
$response->end('404 not found');
}
}); $http->start();

运行在nginx服务器

运行在swoole--http_server服务器
<?php
$http=new swoole_http_server('0.0.0.0',); $http->set([
'worker_num'=>16,
'daemonize'=>1
]); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
//$response->end("hello world");
//$response->status(404);
//$response->end('404 not found');
$pathinfo=$request->server['path_info'];
$in=strrpos($pathinfo,'/');
$filename=substr($pathinfo,$in);
$filename=__DIR__.$filename;
if(is_file($filename)){
$ext=pathinfo($request->server['path_info'],PATHINFO_EXTENSION);
//动态请求处理
if($ext=='php'){
ob_start();
include_once $filename;
$content=ob_get_contents();
ob_end_clean();
$response->end($content);
}else{ //静态请求处理
$content=file_get_contents($filename);
$response->end($content);
}
}else{
$response->status();
$response->end('404 not found');
}
}); $http->start();
设置完成后(daemonize=1时),http_server服务器转入后台作为守护进程运行




<?php
$http=new swoole_http_server('0.0.0.0',); $http->set([
'worker_num'=>,
'daemonize'=>
]); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
//$response->end("hello world");
//$response->status(404);
//$response->end('404 not found');
$pathinfo=$request->server['path_info'];
$in=strrpos($pathinfo,'/');
$filename=substr($pathinfo,$in);
$filename=__DIR__.$filename;
if(is_file($filename)){
$ext=pathinfo($request->server['path_info'],PATHINFO_EXTENSION);
//动态请求处理
if($ext=='php'){
ob_start();
include_once $filename;
$content=ob_get_contents();
ob_end_clean();
$response->end($content);
}else{ //静态请求处理
$mimes=include('mimes.php');
$response->header("Content-type",$mimes[$ext]);
$content=file_get_contents($filename);
$response->end($content);
}
}else{
$response->status();
$response->end('404 not found');
}
}); $http->start();


ZPHP框架
https://github.com/shenzhe/zphp

执行脚手架生成项目


将生成的项目文件全部复制到chat目录下 cp -rf chat_zphp/* chat//

将zphp框架文件全部复制到chat目录下 cp -rf zphp/* chat//

<?php
use ZPHP\ZPHP; $zphp=null;
$mimes=null; $http=new swoole_http_server('0.0.0.0',); $http->set([
'worker_num'=>,
'daemonize'=>
]); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
//$response->end("hello world");
//$response->status(404);
//$response->end('404 not found');
$pathinfo=$request->server['path_info'];
$in=strrpos($pathinfo,'/');
$filename=substr($pathinfo,$in);
$filename=__DIR__.$filename;
if(is_file($filename)){
$ext=pathinfo($request->server['path_info'],PATHINFO_EXTENSION);
//动态请求处理
if($ext=='php'){
/************************
ob_start();
include_once $filename;
$content=ob_get_contents();
ob_end_clean();
$response->end($content);
************************/
$response->status();
$response->end('404 not found');
}else{ //静态请求处理
//$mimes=include('mimes.php');
global $mimes;
$response->header("Content-type",$mimes[$ext]);
$content=file_get_contents($filename);
$response->end($content);
}
}else{
//$response->status(404);
//$response->end('404 not found');
global $zphp;
ob_start();
$zphp->run();
$result=ob_get_contents();
ob_end_clean();
$response->end($result);
}
}); $http->on('workerStart',function($serv,$worker_id){
//require zphp框架目录地址
require __DIR__.DIRECTORY_SEPARATOR.'zphp'.DIRECTORY_SEPARATOR.'ZPHP'.DIRECTORY_SEPARATOR.'ZPHP.php';
//home/wwwroot/default/swoole/www.zphp.com 是应用的地址
$webPath=__DIR__; //项目目录
$configPath='default';//配置的目录的名称
global $zphp;
$zphp=ZPHP::run($webPath,false,$configPath);
global $mimes;
$mimes=require 'mimes.php';
});
$http->start(); /************************************************************************
master //连接的处理(收发管理) 多线程(reactor,heartbeat) epoll
manager //fork 管理worker进程
worker //worker进程 业务逻辑处理
************************************************************************/


代码热更新


<?php
use ZPHP\ZPHP; $zphp=null;
$mimes=null; $http=new swoole_http_server('0.0.0.0',); $http->set([
'worker_num'=>,
'daemonize'=>
]); $http->on('request',function(swoole_http_request $request,swoole_http_response $response){
//print_r($request);
//$response->end("hello world");
//$response->status(404);
//$response->end('404 not found');
$pathinfo=$request->server['path_info'];
$in=strrpos($pathinfo,'/');
$filename=substr($pathinfo,$in);
$filename=__DIR__.$filename;
if(is_file($filename)){
$ext=pathinfo($request->server['path_info'],PATHINFO_EXTENSION);
//动态请求处理
if($ext=='php'){
/************************
ob_start();
include_once $filename;
$content=ob_get_contents();
ob_end_clean();
$response->end($content);
************************/
$response->status();
$response->end('404 not found');
}else{ //静态请求处理
//$mimes=include('mimes.php');
global $mimes;
$response->header("Content-type",$mimes[$ext]);
$content=file_get_contents($filename);
$response->end($content);
}
}else{
//$response->status(404);
//$response->end('404 not found');
$_GET=$_POST=$_COOKIE=$_REQUEST=[];
if(!empty($request->get)){
$_GET=$request->get;
$_REQUEST +=$_GET;
}
if(!empty($request->post)){
$_POST=$request->post;
$_REQUEST +=$_POST;
}
if(!empty($request->cookie)){
$_COOKIE=$request->cookie;
}
global $zphp;
ob_start();
$zphp->run();
$result=ob_get_contents();
ob_end_clean();
$response->end($result);
}
}); $http->on('workerStart',function($serv,$worker_id){
//require zphp框架目录地址
require __DIR__.DIRECTORY_SEPARATOR.'zphp'.DIRECTORY_SEPARATOR.'ZPHP'.DIRECTORY_SEPARATOR.'ZPHP.php';
//home/wwwroot/default/swoole/www.zphp.com 是应用的地址
$webPath=__DIR__; //项目目录
$configPath='default';//配置的目录的名称
global $zphp;
$zphp=ZPHP::run($webPath,false,$configPath);
global $mimes;
$mimes=require 'mimes.php';
});
$http->start(); /************************************************************************
master //连接的处理(收发管理) 多线程(reactor,heartbeat) epoll
manager //fork 管理worker进程
worker //worker进程 业务逻辑处理
************************************************************************/
D:\phpStudy\WWW\swoole\chat\apps\ctrl\main\main.php
public function main()
{
$project = Config::getField('project', 'name', 'zphp');
$data = $project." runing in swoole!\n";
$params = $_REQUEST;//Request::getParams();
if(!empty($params)) {
foreach($params as $key=>$val) {
$data.= "key:{$key}=>{$val}\n";
}
}
print_r($data);
return $data;
}







swoole在线聊天学习笔记的更多相关文章
- CUDA C Programming Guide 在线教程学习笔记 Part 4
▶ 图形互操作性,OpenGL 与 Direct3D 相关.(没学过,等待填坑) ▶ 版本号与计算能力 ● 计算能力(Compute Capability)表征了硬件规格,CUDA版本号表征了驱动接口 ...
- CUDA C Best Practices Guide 在线教程学习笔记 Part 2
10. 执行配置优化 ● 一个 SM中,占用率 = 活动线程束的数量 / 最大可能活动线程束的数量.后者保存在设备属性的 maxThreadsPerMultiProcessor 分量中(GTX10 ...
- CUDA C Best Practices Guide 在线教程学习笔记 Part 1
0. APOD过程 ● 评估.分析代码运行时间的组成,对瓶颈进行并行化设计.了解需求和约束条件,确定应用程序的加速性能改善的上限. ● 并行化.根据原来的代码,采用一些手段进行并行化,例如使用现有库, ...
- CUDA C Programming Guide 在线教程学习笔记 Part 10【坑】
▶ 动态并行. ● 动态并行直接从 GPU 上创建工作,可以减少主机和设备间数据传输,在设备线程中调整配置.有数据依赖的并行工作可以在内核运行时生成,并利用 GPU 的硬件调度和负载均衡.动态并行要求 ...
- CUDA C Programming Guide 在线教程学习笔记 Part 13
▶ 纹理内存访问补充(见纹理内存博客 http://www.cnblogs.com/cuancuancuanhao/p/7809713.html) ▶ 计算能力 ● 不同计算能力的硬件对计算特性的支持 ...
- CUDA C Programming Guide 在线教程学习笔记 Part 11
▶ 数学函数 ● 舍入函数,考虑被舍入参数有双精度浮点和单精度浮点,舍入方式有区别,舍入结果有整形.长整形和长长整形,所以共有以下舍入函数. // math_functions.h extern __ ...
- CUDA C Programming Guide 在线教程学习笔记 Part 9
▶ 协作组,要求 cuda ≥ 9.0,一个简单的例子见 http://www.cnblogs.com/cuancuancuanhao/p/7881093.html ● 灵活调节需要进行通讯的线程组合 ...
- CUDA C Programming Guide 在线教程学习笔记 Part 8
▶ 线程束表决函数(Warp Vote Functions) ● 用于同一线程束内各线程通信和计算规约指标. // device_functions.h,cc < 9.0 __DEVICE_FU ...
- CUDA C Programming Guide 在线教程学习笔记 Part 7
▶ 可缓存只读操作(Read-Only Data Cache Load Function),定义在 sm_32_intrinsics.hpp 中.从地址 adress 读取类型为 T 的函数返回,T ...
随机推荐
- mysql学习指令
mysql 用户管理和权限设置 参考文章:http://www.cnblogs.com/fslnet/p/3143344.html Mysql命令大全 参考文章: http://www.cnblogs ...
- 测试人员如何使用Git
测试人员如何使用Git? 首先Git的安装,这里不多做阐述,直接去Git官方网站下载后并傻瓜式安装即可. 如何判定已安装好Git呢? ------------- 随便打开一个目录,鼠标右键点击可看到 ...
- UIViewContentModel图解+文解
typedef NS_ENUM(NSInteger, UIViewContentMode) { //图片拉伸填充至整个UIImageView(图片可能会变形),这也是默认的属性,如果什么都不设置就是它 ...
- 【剑指Offer面试编程题】题目1388:跳台阶--九度OJ
题目描述: 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入包括一个整数n(1<=n< ...
- 【Go语言系列】2.2、Go语言基本程序结构:关键字与标识符
什么是标识符 标识符用来命名变量.类型等程序实体.标识符是指Go语言对各种变量.方法.函数等命名时使用的字符序列,标识符由若干个字母.下划线_.和数字组成,且第一个字符必须是字母.通俗的讲就是凡可以自 ...
- Deepctr框架代码阅读
DeepCtr是一个简易的CTR模型框架,集成了深度学习流行的所有模型,适合学推荐系统模型的人参考. 我在参加比赛中用到了这个框架,但是效果一般,为了搞清楚原因从算法和框架两方面入手.在读代码的过程中 ...
- 机器学习中 为何要使用 独热编码 one-hot
背景 接触tensorflow时,学习到mnist,发现处理数据的时候采取one-hot编码,想起以前搞FPGA状态机遇到过格雷码与独热码. 解析: 将离散型特征使用one-hot编码,确实会让特征之 ...
- ElasticSearch入门了解
什么是Elasticsearch: Elasticsearch,分布式,高性能,高可用,可伸缩的搜索和分析系统 1.什么是搜索? 搜索,就是在任何场景下,找寻你想要的信息,这个时候,会输入一段你要搜索 ...
- Linux:Shell-Bash基本功能
1.历史命令 history [选项] [历史命令保存文件] 选项:-c 清空历史命令 -w 把缓存中的历史命令写入历史命令保存文件 ~/.bash_history 历史命令默认保存1000条,可以 ...
- Plcsim 模拟IO访问故障 OB122组织块
假设在OB1 中用 如下指令 T PQW20 实际在组态的时候就没有QW20 这个地址 所以会显示访问IO 错误 我在OB122 中设置一个变量 进入一次 加1 可以看到每个扫描周期都要调用一次OB1 ...