The other problem I had with Laravel Task Scheduling was that i really only wanted something to handle the scheduling. I already had my logical unit of work defined the task that needed to be completed and I didn’t want to have to rebuild it. Thankfully, that is all that cron-expression brings to the table. It literally takes a string that is the first 5 arguments of a cron task and parses them. it will tell you if it’s due to run, it will tell you when it will run next and when it ran last.

Most of the solutions I threw out, I did so because they were either unmaintained or they did too much. cron-expression is a discrete piece of code that does a single test.

Really, the only problem I ran into was the almost nonexistent documentation. The Readme on the project gives you the basics but the examples are pretty simple and not always useful. Thankfully, Michael Dowling, the author, wrote a great article about WHY he built it and also shows a lot of examples on HOW to use it. If you are going to use this code, make sure you read “Cron Expression Parsing in PHP” . Not only is Michael a good writer, it is very informative.

:Conclusion

If you are looking for “Do this at that time” there are a lot of PHP based solutions available for you. If you are early enough in your design process to make framework choices, look seriously at the larval solution, although there are others that are framework agnostic also.

Side Note

I ad spent countless hours trying to create the solution myself. Since everything I was working with will be inside a MySQL database, I envisioned a convoluted and ultimately beautiful SQL statement that would do all of the calculations for me and tell me exactly when something was to run. I got so lost in solving the problem, I forgot to look to see if someone had already solved it.

Repeat after me. My idea is not a snowflake, someone else has done it.

USE THE SOURCE!

This was more for me than you.

― Cal Evans (@CalEvans) November 16, 2016

根据pathinfo访问对应得controller,如ip:port/home/index/index则会访问home目录下的IndexController的index方法;如果不指定pathinfo则访问home目录下的IndexController的index方法

service service层: $sql = 'select * from admin_user where id=1'; $data['sql'] = $sql; $data['info'] = yield table('admin_user')->where(['id'=>1])->find(); return $data; controller层: //使用1-封装在service层,controller层也得写yield $testservice = new TestService(); $data = yield $testservice->test(); return $data; Cache-redis(已经是异步非阻塞)

配置:

return [ 'redis'=>[ 'ip' => 'localhost', 'port' => 6379, 'select' => 0, 'password' => '', 'asyn_max_count' => 10, ] ];

使用:

$data = yield Db::redis()->cache('abcd');

只要在config目录下配置cache文件,即可在业务里调用缓存方法,如:

数据库 mysql(已经是异步非阻塞)

在config下配置mysql的配置文件,即可在业务中使用,你可以使用以下方法查询数据

$data = yield Db::table()->query('select* from admin_user'); $a = yield DB::table()->query('select*from admin_user where id =1'); $userinfo = yield table('admin_user')->where(['id'=>1])->find(); http client(已经是异步非阻塞) $httpClient = new HttpClientCoroutine(); $data = yield $httpClient->request('http://speak.test.com/'); 框架全部封装好.怎么样,这异步用起来是不是很简单^_^ mongo(还是同步阻塞的)

Swoole + zphp 改造为专门用来开发接口的框架的更多相关文章

  1. Android JNI 本地开发接口

    前言 我们为什么要用JNI --> 高效.扩展 高效:Native code效率高,数学运算,实时渲染的游戏上,音视频处理 (极品飞车,opengl,ffmpeg,文件压缩,图片处理-) 扩展: ...

  2. C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 多系统开发接口 - 苹果客户端开发接口

    最近工作上需要,给苹果客户端开发接口,实现集中统一的用户管理,下面是接口调用参考. 1: 获取OpenId? http://127.0.0.1/GetOpenId.ashx?username=Admi ...

  3. 准备.Net转前端开发-WPF界面框架那些事,值得珍藏的8个问题

    题外话 不出意外,本片内容应该是最后一篇关于.Net技术的博客,做.Net的伙伴们忽喷忽喷..Net挺好的,微软最近在跨平台方面搞的水深火热,更新也比较频繁,而且博客园的很多大牛也写的有跨平台相关技术 ...

  4. 关于web开发前端h5框架的选择

    关于web开发前端h5框架的选择 看了很多移动版框架都是基于app混合式开发的,不是单独h5网站的基于h5开发的web框架从组件丰富度,兼容性,相关教程来说bootstrap还是最好的react和vu ...

  5. iOS 开发之照片框架详解(2)

    一. 概况 本文接着 iOS 开发之照片框架详解,侧重介绍在前文中简单介绍过的 PhotoKit 及其与 ALAssetLibrary 的差异,以及如何基于 PhotoKit 与 AlAssetLib ...

  6. HIbernate学习笔记(二) hibernate对象的三种状态与核心开发接口

    1.在hibernate中持久化对象有三个状态,这个面试时可能会问到: (1)transient瞬时态:在数据库中没有与之匹配的数据,一般就是只new出了这个对象,并且在session缓存中也没有即此 ...

  7. NET Core开发-使用Nancy框架

    NET Core开发-使用Nancy框架 Nancy简介 Nancy是一个轻量级的独立的框架,下面是官网的一些介绍: Nancy 是一个轻量级用于构建基于 HTTP 的 Web 服务,基于 .NET ...

  8. iOS 开发之照片框架详解之二 —— PhotoKit 详解(下)

    本文链接:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-three.html 这里接着前文<iOS ...

  9. iOS 开发之照片框架详解

    转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework.html 一. 概要 在 iOS 设备中,照片和视频是相当重 ...

随机推荐

  1. loadView在App启动时到底都干了些什么?

    loadView在App启动时到底都干了些什么? 查阅苹果官方文档如下: 1. 当你访问一个ViewController的view属性时,如果此时view的值是nil,那么,ViewControlle ...

  2. 3、DOM操作

    一.认识DOM 文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树). 先来看看下面 ...

  3. OSG绘制几何图形

    在OSGMFC程序基础上修改OSG_MFC类的方法,如下: void cOSG::InitSceneGraph(void) { // Init the main Root Node/Group mRo ...

  4. curl获得http响应码 302 和绑定host

    shell curl 取得HTTP返回的状态 获取状态码 curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com 获取时间   curl ...

  5. ORA-15260: permission denied on ASM disk group

    向ASM磁盘组添加新的磁盘的时候,报了以下错误: $ sqlplus '/as sysdba' SQL*Plus: Release 11.2.0.4.0 Production on Sat Dec 2 ...

  6. Java String类详解

    Java String类详解 Java字符串类(java.lang.String)是Java中使用最多的类,也是最为特殊的一个类,很多时候,我们对它既熟悉又陌生. 类结构: public final ...

  7. vs2015社区版不支持installshield

    开始学习vs了 下一步就是在这个平台上提升技术咯. 写了老师上课讲的算法 生成了个VB程序结果不能在别的电脑上运行 .幸好我自己测试了下.要是直接拿去学校不是很~ 然后我就想到当初接触易语言时候的搞静 ...

  8. Java: xml转换

    java对于xml的转换有很多种,比较有名的有:DOM, DOM4J, JDOM, SAX.这里要介绍的是javax.xml包的对xml文件的转换.相比于前面几种是最简单的. 直接上代码: Stude ...

  9. centos python nginx uwsgi

    先更新系统,并安装编译环境等等. yum update yum install python python-devel libxml2 libxml2-devel python-setuptools ...

  10. bzoj 4358 permu

    比较容易想到莫队算法+线段树,但是这样时间复杂度是O(nsqrtnlogn)无法通过,考虑如果不进行删除操作,只有添加操作的话那么并查集就可以实现了,于是可以设定sqrtn块,每个块范围为(i-1)* ...