- Joomla Store
- Parser written in php
Task: a button is created in the admin panel that should launch the parser. Since parsing takes a long time (several hours), you need to run it in the background so that the browser can be closed. When you click on the button again from the admin panel, it should throw on the page with the indicator, they say, the process is already running, wait.
Ideally, if the crown is already running, then the indicator should also display this.
How to do it all?
You need to store this progress indicator somewhere.
In a * nix environment, it is customary to simply create a file, for example, "parser.pid", in which a single number is written – the number of the running process. When the process finishes, it deletes its pid file as the last action.
You can also, by starting the parser, create a file in the designated place in which to write the process id – the id can be obtained directly in php via
In the admin panel, see if there is such a file, and it would also be good to check if the process with this id is alive: by executing a shell command, or, if POSIX functions are not disabled ,
posix_kill( $pid, 0) . The latter sends a null signal, which does nothing, to the process. F-i will return
true if the sending succeeded, otherwise
So you can find out from any place if the process is alive. And then show, run, etc. according to the logic of your application.