<?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在线聊天学习笔记的更多相关文章

  1. CUDA C Programming Guide 在线教程学习笔记 Part 4

    ▶ 图形互操作性,OpenGL 与 Direct3D 相关.(没学过,等待填坑) ▶ 版本号与计算能力 ● 计算能力(Compute Capability)表征了硬件规格,CUDA版本号表征了驱动接口 ...

  2. CUDA C Best Practices Guide 在线教程学习笔记 Part 2

    10. 执行配置优化 ● 一个 SM中,占用率 = 活动线程束的数量 / 最大可能活动线程束的数量.后者保存在设备属性的  maxThreadsPerMultiProcessor  分量中(GTX10 ...

  3. CUDA C Best Practices Guide 在线教程学习笔记 Part 1

    0. APOD过程 ● 评估.分析代码运行时间的组成,对瓶颈进行并行化设计.了解需求和约束条件,确定应用程序的加速性能改善的上限. ● 并行化.根据原来的代码,采用一些手段进行并行化,例如使用现有库, ...

  4. CUDA C Programming Guide 在线教程学习笔记 Part 10【坑】

    ▶ 动态并行. ● 动态并行直接从 GPU 上创建工作,可以减少主机和设备间数据传输,在设备线程中调整配置.有数据依赖的并行工作可以在内核运行时生成,并利用 GPU 的硬件调度和负载均衡.动态并行要求 ...

  5. CUDA C Programming Guide 在线教程学习笔记 Part 13

    ▶ 纹理内存访问补充(见纹理内存博客 http://www.cnblogs.com/cuancuancuanhao/p/7809713.html) ▶ 计算能力 ● 不同计算能力的硬件对计算特性的支持 ...

  6. CUDA C Programming Guide 在线教程学习笔记 Part 11

    ▶ 数学函数 ● 舍入函数,考虑被舍入参数有双精度浮点和单精度浮点,舍入方式有区别,舍入结果有整形.长整形和长长整形,所以共有以下舍入函数. // math_functions.h extern __ ...

  7. CUDA C Programming Guide 在线教程学习笔记 Part 9

    ▶ 协作组,要求 cuda ≥ 9.0,一个简单的例子见 http://www.cnblogs.com/cuancuancuanhao/p/7881093.html ● 灵活调节需要进行通讯的线程组合 ...

  8. CUDA C Programming Guide 在线教程学习笔记 Part 8

    ▶ 线程束表决函数(Warp Vote Functions) ● 用于同一线程束内各线程通信和计算规约指标. // device_functions.h,cc < 9.0 __DEVICE_FU ...

  9. CUDA C Programming Guide 在线教程学习笔记 Part 7

    ▶ 可缓存只读操作(Read-Only Data Cache Load Function),定义在 sm_32_intrinsics.hpp 中.从地址 adress 读取类型为 T 的函数返回,T ...

随机推荐

  1. Java连载80-数字类格式、随机数、BigDecimal

    一.数字类 1.关于数字格式化:java.text.DecimalFormat; 2.数字格式元素: # 任意数字 , 千分位 . 小数点 0 不够补零 package com.bjpowernode ...

  2. FFmpeg笔记--vcodec和-c:v,-acodec和-c:a的区别?

    在看ffmpeg命令的时候经常会看到有些地方使用--vcodec指定视频解码器,而有些地方使用-c:v指定视频解码器,那这两个有没有区别呢? ffmpeg的官方文档: -vcodec codec (o ...

  3. Eclipse之Cannot open Eclipse Marketplace

    今天给eclipse安装插件的时候出现各种cannot connect to...的问题, 想打开eclipse marketplace来安装插件出现Cannot open Eclipse Marke ...

  4. python 中的 *args 和 **kwargs

    在阅读Python代码时,经常会看到如下函数的定义: def fun(*args, **kwargs): 很多同学可能会对此感到困惑,这个 * args和 **kwargs是什么东西.为啥会在源码中应 ...

  5. 吴裕雄--天生自然PYTHON爬虫:使用BeautifulSoup解析中国旅游网页数据

    import requests from bs4 import BeautifulSoup url = "http://www.cntour.cn/" strhtml = requ ...

  6. #写一个登陆的程序 ( 1.最多登录失败3次 2.登陆成功,提示欢迎XX登录,今天的日期是XXX,程序结束 3.要检验输入是否为空,账户和密码不能为空 4.账户不区分大小写)

    import datetime import MySQLdb today=datetime.datetime.today() username=str(input('请输入账户:')) passwd1 ...

  7. java并发之CopyOnWriteArraySet

    java并发之CopyOnWriteArraySet CopyOnWriteArraySet是基于CopyOnWriteArrayList实现的,持有CopyOnWriteArrayList的内部对象 ...

  8. ORACLE锁表问题

    1.查询锁表的信息 select sess.sid,sess.serial#, lo.oracle_username,lo.os_user_name, ao.object_name,lo.locked ...

  9. Hibernate all-delete-orphan[转]

    博客分类: SSH   当关联双方存在父子关系,就可以在 set 处设定 cascade 为 all-delete-orphan 所谓父子关系,即指由父方控制子方的持久化圣明周期,子方对象必须和一个父 ...

  10. SciPy fftpack(傅里叶变换)

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...