S
S
Sorin Ciobanu2017-08-28 20:18:40
Yii
Sorin Ciobanu, 2017-08-28 20:18:40

How to automate script execution in Yii?

Good day.
There is a controller that performs a specific function. There is a need to automate this process, say every day at 00:00 this action should be performed.
The script itself must import data from xml files to update the database with new information. The import process is not fast and takes about an hour. To relieve the load from the server, the import is performed in fragments, data is constantly received by the browser and an ajax request is sent back for further execution. How to automate the process in this case so that the process also goes on stage by stage.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
coderisimo, 2017-08-28
@coderisimo

Console commands can be called with CRONOM. From here - schedule the cron, which at the right time launches the execution of certain "consoles" ( www.yiiframework.com/doc-2.0/guide-tutorial-consol... .
You can make the tasks more flexible. Then, at startup, the script checks whether there are current tasks (you can store them, for example, in a database), and if "there is something" performs. Completed - marked as completed.

M
mitaichik, 2017-08-28
@mitaichik

As said above - use console commands. To minimize memory consumption, use streaming xml parsers, to minimize the load on the database, use batch or batch inserts, updates. To give others time - you can insert a slip, but this is all bullshit, in multiprocessor and multi-core systems it is unlikely that one php process will hang the system, so the other ones stop. You can take the process.
To run - cron. There is also a crown-like solution for yii, alas, I don’t remember the name, we use it - no complaints.

A
Andrey Sanych, 2017-08-28
@mountpoint

Yii 2 has console commands for this , for Yii 1 I don't know.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question