php - How to implement a scheduled task to operate on data in the database?
PHPz
PHPz 2017-05-27 17:42:05
0
8
1184

We are currently developing a project using the laravel framework. The project requires some data. The required data is obtained by performing associated queries, calculations, and processing on dozens of tables in the database. Due to the large amount of data, the company requires writing A scheduled task starts executing at every night at 0 o'clock and ends after all the data has been processed. I have now written a method in the laravel controller to process the data in the database. Now I only need to execute this method in a regular loop to achieve the function.

But now I don’t know how to execute it regularly? Is it executed in php cli mode? Or use artisan console to execute? Looking for some advice?

PHPz
PHPz

学习是最好的投资!

reply all(8)
某草草

crontab Use the Linux wget or curl command to access your controller through HTTP requests.

PHPzhong

1. For large amounts of data, it is best not to pull it out of the application layer and write a MySQL stored procedure or function. (The call can be called through mysql event), this processing will save resources very much.

2. Still writing to the stored procedure, you can cooperate with the crond scheduled task in Linux for scheduled processing.

曾经蜡笔没有小新

Laravel’s Scheduling I think fits your needs very well. The Chinese documentation is here.
http://d.laravel-china.org/do...

过去多啦不再A梦

Laravel has a task scheduling function. It is recommended to read more documents~

左手右手慢动作

According to your situation, the simplest one is laravel's task scheduling

淡淡烟草味

contrab

淡淡烟草味

This depends on the needs of your company. If there is operation and maintenance, you can write a method to operate the data yourself, and let the operation and maintenance write a script to request this method regularly. If there is no operation and maintenance and your boss will not let you touch the server, you can choose to write a PHP script to manipulate the data, use sleep and loops to do it, put the file in the connection, and use the header function to access the request link

巴扎黑

Let me recommend several libraries for scheduled tasks. Use composer to load
Dispatcher Laravel-based scheduled task management
swoole-crontab swoole-based timer program that supports second-level processing
jobby A PHP scheduled task manager
cronlingo Express crontabs as human friendly phrases
If you have nothing to do, you can go to awesomes- View it in php
If you can’t read English, I have a backup here and you can also view it by clicking here to jump

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!