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 ...
随机推荐
- 隐藏浏览器body的滚动条,并进行滚动
在使用html2canvas插件的时候,发现截图完成后右侧区域被覆盖了一点,后面才发现是滚动器占了位置 网上有些解决滚动条的方法,不过他们都是相对盒子的,而我这个是对body的 最终发现引用下面这个c ...
- Python可视化界面编程入门
Python可视化界面编程入门具体实现代码如所示: (1)普通可视化界面编程代码入门: import sysfrom PyQt5.QtWidgets import QWidget,QApplicati ...
- Centos7 VNC远程桌面服务安装配置
1.服务器版本 CentOS Linux release 7.7.1908 (Core) 首先系统安装了GUI界面 # ln -sf /lib/systemd/system/graphical.tar ...
- ZCGL大数据项目优化组件布置
1.经JMeter并发性能测试,每个HBaseService服务的并发请求上限大概是1K,为了支持5W个并发请求量,需要增加部署节点,相应需要增加部署路由网管Zuul,为了隐藏多个路由网管Zuul的I ...
- shiro用ajax方式登录
用了shiro一段时间了,但是有点受不了它请求登录如果验证不通过直接跳的是loginUrl…所以我想很多人想用ajax实现shiro的登录直接在回调函数里面通过js显示出错信息吧. 今天查了一天的资料 ...
- python学习笔记(三)---高级特性
一.切片 取无数多个list元素 不用一个个取得笨方法就用切片 对这种经常取指定索引范围的操作,用循环十分繁琐,因此,Python提供了切片(Slice)操作符,能大大简化这种操作. 对应上面的问题, ...
- Python—处理Excel表格
一.使用xlrd和xlwt这两个库来处理excel,即xlrd是读excel的库,xlwt是写excel的库 1.使用 xlrd 读取Excel数据 # -*- coding:utf-8 -*- im ...
- PHP几个快速读取大文件例子
PHP几个快速读取大文件例子 感谢 把我给崩了 的投递 时间:2014-10-16 来源:三联 在PHP中,对于文件的读取时,最快捷的方式莫过于使用一些诸如file.file_get_contents ...
- Python面试2未完待续
Python面试重点(基础篇) 注意:只有必答题部分计算分值,补充题不计算分值. 第一部分 必答题(每题2分) 简述列举了解的编程语言及语言间的区别? c语言是编译型语言,运行速度快,但翻译时间长py ...
- GNS3 模拟免费ARP
R2 : conf t int f0/0 no shutdown ip add 192.168.1.254 255.255.255.0 end R1 : conf t int f0/0 no shut ...