1. yield的函数,就是一个Generator对象的生成器,调用此类函数,不会立即执行函数体中的代码
  2. 关于用于多任务处理,
    任务(task)是Generator对象的简单包装对象,
    任务管理器(Scheduler)对队列中任务分别迭代,直到所有任务被执行完(循环完),
    系统调用(SysCall)是一个callback的包装,将当前执行的任务及管理器作为参数,
    协程堆栈(StackedCoroutine) 支持任务协程中运行子协程函数,以便对功能做更小粒度的封装。
    在任务中执行系统调用,一个callback(Task,  Scheduler), 在执行过程中,可将task继续加入到调度器(Scheduler)中,如Scheduler->addTask(task),或是从调度器中删除,即不执行addTask方法, 如有需要之后再从别的Task中将之前的Task加入进来
  3. 多任务处理在异步io中的应用

    参考 http://www.oschina.net/translate/cooperative-multitasking-using-coroutines-in-php

以久没有进行socket编程,记录下供以后查阅

  1. 阻塞与非阻塞, 针对io过程中进(线)程状态,是否再分配cpu时间片
  2. 同步与异步, 针对调用功能返回结果而言
  3. 多路复用, 对于 Socket 来说,能同时处理多个连接的模型都应该被称为多路复用,目前比较常用的有 select/poll/epoll/kqueue 这些 IO 模型
  4. php的socket编程,了解以下扩展

     

 

核心概念

  1. Object基类,构造函数()初始化属性
  2. Behavior行为, 一般注册Component的事件,公用方法及属性供Component调用
  3. Component组件, 事件管理(on, off, trigger, attach绑定事件 )、动态属性管理(__get)、动态方法管理(__call)
  4. ServiceLocator容器, 现在框架标配
  5. Module模块,有自己的controller, view, widget或静态资源
  6. Application应用(web, console), 继承模块, 引导扩展、组件; handle请求,并响应结果(MVC执行流程)
  7. Yii全局对象, 大量常用的静态方法(自动加载函数、t函数、设置属性函数、日志函数), 静态属性($app, 容器,别名,类名映射)
  8. ActionFilter过滤器, 在执行action之前进行某种操作, 监听Controller::EVENT_BEFORE_ACTION事件, 设置only属性数组,可只对某些action起作用 @see ActionFilter::isActive()
  9. Authentication 身份认证,@see Yii\web\User, IdentityInterface
  10. Authorization 授权,  @see yii\filters\AccessControl, AccessRule

MVC的运行

根据id找到模块或设置ctrl路径的Controller对象,
运行Ctrl->runAction() 方法
-a)执行berforAction(),  包括模块及自身的
-b)执行$action->runWithParams(), 执行action::berforeRun(), run(), afterRtun()
-c)执行afterAction(), 包括自身及模块的

执行流程拦截点@see ActionFilter
-1) (module, ctrl)::berforeAction()返回false
-2) (module, ctrl)::EVENT_BEFORE_ACTION, 事件监听
-3) action->beforeRun() 返回 false

过滤结果拦截点:
-1> (module, ctrl)::afterAction()
-2> (module, ctrl)::EVENT_AFTER_ACTION, 事件监听

改变默认执行流程:
-1)改变action, 设置ctrl->actions(), 映射新的Action类, @see ctrl::createAction(id)
-2)  改变ctrl加载,设置app|module的controllerMap属性,@see Module::createController

视图路径的渲染:
-1) layout路径的查询, 优先 module->layoutPath, 后app->layoutPath, @see ctrl::findLayoutFile()
-2) 视图的路径查询, @see View::findViewFile()
a. @path别名路径;
b. //path App::getViewPath();
c. /path Module::getViewPath();
d. ViewContextInterface, 如widget, ViewContextInterface::getViewPath()
e. $this->getViewFile(),  最后的防线

静态资源的发布:
a. View运行AssetBundle::register($view) ,
b. 调用View::getAssetManager()->getBundle($name), 得到AssetBundle
c. 运行 AssetBundle->publish($am) 进行发布到网站根目录并设置 css, js属性
d. 在视图文件设置点,一般是layout文件, 如View::head(), begeinBody(), endBody()
e. 在View::endBody() 中调用AssetBundle::registerAssetFiles($view) 获取之前设置发布后的js, css

参考:http://www.yiiframework.com/doc-2.0/index.html

排行
https://packagist.org/explore/popular

router [mvc]
https://github.com/nikic/FastRoute

monolog [log]
https://github.com/Seldaek/monolog

doctrine2 [orm]
https://github.com/doctrine/doctrine2

symfony/finder [filesystem]
https://github.com/symfony/finder

 

php开源的调试工具
new Debugbar -> addCollector  => Collector 收集数据 => render(js)

  • 数据收集(集合) DataCollector
  • 显示格式化工具 DataFormatter
  • 调试数据存储 Storage
  • js渲染工具 Resources(widget, debugbar)

扩展:
创建 Collector 继承 DataCollector, 根据需要创建 Resources/widgets/<name>

github: https://github.com/maximebf/php-debugbar
document: http://phpdebugbar.com/docs/

 

参考 http://php.net/manual/en/refs.calendar.php

https://github.com/fguillot/kanboard

PHP之依赖注入容器pimple
https://github.com/silexphp/Pimple
SplObjectStorage类

SimpleLogger
Syslog and Text files
https://github.com/fguillot/simpleLogger

SimpleValidator
https://github.com/fguillot/SimpleValidator

iCal iCalendars
https://github.com/markuspoerschke/iCal

Base32
https://github.com/NTICompass/PHP-Base32

  • 订阅者注册推送地址,关注的事件
  • 服务端将消息存储redis队列
  • 服务端开N个进程,读取redis队列并推送到订阅者url
  • 推送错误进入错误队列
  • 服务定时发送错误队列消息

原型

  • swoole->addProcess(swoole_process)增加的进程不能start()
  • process结束后会被master进程再次创建,所以要么阻塞或进epoll循环
  • 参考 http://wiki.swoole.com/wiki/page/390.html
  • 与worker或task进程通信参考  http://wiki.swoole.com/wiki/page/363.html

 

  1. 在server->start()之前,不要将资源连接用于共用(static或设置到server->var中) worker或task是从主进程中fork,进程间不能共用资源连接
  2. 尽可能在start前加载足够少的文件、对象