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 ...
随机推荐
- Using SmartAssembly with MSBuild
SmartAssembly 6 SmartAssembly 6 documentation Building your assembly Using SmartAssembly with MSBuil ...
- 用python发送qq邮件
一.需要开启smtp服务,获取授权密码. 在qq邮箱的设置里开启smtp 二.代码 # -*- coding:utf-8 -*- import smtplib from email.mime.text ...
- HTTP出现前的协议
前言 再HTTP普及之前,也就是从互联网的诞生期至今,曾出现过各式各样的协议.在HTTP规范确立之际,制定者们参考了那些协议的功能. 正文 1.FTP(File Transfer Protocol) ...
- redis之string数据类型常用方法总结
目录 redis 字符串(string)[需要掌握] 特点 语法 redis 字符串(string)[需要掌握] 特点 一个键能存储512MB数据 string类型是二进制安全的,可以存储任何数据,比 ...
- myBatis 操作 mysql时,使用 like 关键进行模糊查询的方法
参考:https://blog.csdn.net/rainbow702/article/details/50519424 like CONCAT('%', #{mkName}, '%')
- Linux centosVMware shell脚本中的逻辑判断、文件目录属性判断、if特殊用法、case判断
一.shell脚本中的逻辑判断 格式1:if 条件 ; then 语句; fi 格式2:if 条件; then 语句; else 语句; fi 格式3:if …; then … ;elif …; th ...
- dstat 监控命令详解
一.工具介绍 dstat的man手册对于该工具的解释: dstat - versatile tool for generating system resource statistics 系统资源多用途 ...
- 「USACO5.4」奶牛的电信Telecowmunication
传送门 Luogu 解题思路 题目要求的是最小割点集,考虑用最小割来做. 所有边容量为1,直接求最小割? 这样肯定会出错,比如这种情况: 从最左边的点到最右边的点的最小割为2,但是答案是1,只要破坏中 ...
- PyQt5点击菜单栏弹出新窗口,解决新窗口闪退的实现方法
实现的功能为:当点击菜单中某个菜单时,会弹出一个新窗口,下面就列出部分代码 def mail_setting(self): log.debug("open mail settings&quo ...
- Java枚举类型enum使用详解
java的Enum枚举类型终于在j2se1.5出现了.之前觉得它只不过是鸡肋而已,可有可无.毕竟这么多年来,没有它,大家不都过得很好吗?今日看<Thinking in Java>4th ...