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.mysql
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.redis
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.sql
: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.express
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.less
USE THE SOURCE!異步
This was more for me than you.ide
― 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(仍是同步阻塞的)