search

Home  >  Q&A  >  body text

php - How to implement a scheduled task to operate on data in the database?

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?

PHPzPHPz2779 days ago1226

reply all(8)I'll reply

  • 某草草

    某草草2017-05-27 17:44:05

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

    reply
    0
  • PHPz

    PHPz2017-05-27 17:44:05

    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.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-27 17:44:05

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

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-27 17:44:05

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

    reply
    0
  • ringa_lee

    ringa_lee2017-05-27 17:44:05

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

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-27 17:44:05

    contrab

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-27 17:44:05

    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

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-27 17:44:05

    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

    reply
    0
  • Cancelreply