Swoole + zphp 改造为专门用来开发接口的框架

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(还是同步阻塞的)

posted @ 2016-12-06 17:51  3002059249  阅读(339)  评论(0编辑  收藏  举报