Use php-cli and task plan to synchronize orders.
1. application scenarios
You need to go to the platform website to obtain your order information through APIS. There are two key points:
(1)User traversal, We must traverse each user to get their orders;
(2)Regular acquisition, acquisition of user orders is not once and for all, it does not mean that there is no next second, we must set a proper time interval to get him.
2. Implement User traversal by traversing the table
To solve the problem of user traversal, we can place all users in a table with an auto-increment id in the table. We calculate the maximum value of the id, then, the row whose id is equal to the specified value is cyclically retrieved from 0, so that the whole table can be traversed.
3. Regular acquisition methods
(1)Fetch is continuously executed with an endless loop, and sleep is performed at intervals.
Considering that this fetch action may be required almost every moment when there are more users, do you still need to use the task plan? Why not directly use the while (true) endless loop? It can also be used with sleep actions.
This solution does not take into account the fact that php is a script file and does not automatically recycle garbage. It seems that it can also be manually recycled, but it is always troublesome and full of uncertainty. As long as the page is executed, he will clean up and clear it. Therefore, do not use troublesome methods to solve simple things.
(2)Execute fetch periodically with the task plan. If it is already in progress, no operation is performed until the next scheduled time.
This method still uses task scheduling, and the task scheduling is very powerful. By default, the current instance can be executed without starting a new instance. That is to say, if the execution time of an action exceeds the task schedule interval, the first task is not completed yet when the current task is started, in this case, it automatically does not repeat the execution. For example:
The above method of implementing the order synchronization function using php-cli and task plan is to share all the content with you in the editor. I hope you can give us a reference and support for the customer's house.