A
A
artem782017-07-14 00:18:16
Parsing
artem78, 2017-07-14 00:18:16

What is the best way to implement a "long-playing" parser as a plugin for Wordpress?

I am writing a WP plugin for automatically adding / updating products in Woocommerce from a donor site. The parsing process should be run every few days via wp cron and will last about 1-2 hours. Because the execution time of php scripts on the server is limited to a few minutes and due to the fact that the parser can crash due to errors, it is necessary to implement the ability to perform work in parts. To do this, while the parser is running, the current processed product is written to the transient option. At the next start, work continues from the position saved in the state. If all items are processed, the option is removed. Now the question arose of how best to implement the re-launch of the parser after performing partial processing. Two options come to mind:

  1. At each start, define max_execution_timeand assign a single task after max_execution_time+ a few seconds. If the goods are over, then delete this task.
  2. The second option involves creating an auxiliary task with a launch frequency of once every 5 minutes, which, if there is a saved state and if the parser is not currently working, will start it again.

What do you think is the best option for this task? Can you suggest other options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2017-07-16
@ruvasik

As I understand it, you cannot set an unlimited amount of time through set_time_limit.
In this case, option 2 is the most reliable, but a little more difficult to implement.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question