A WordPress plugin I have created needs to run a plugin function overnight.
I currently run it on a command line using curl http://pathtopluginfunction
. I have enabled this by creating an end point using wp-json
. It "works", however, this however this is clearly a massive hack.
A big problem is that the output is buffered before being output (according to how http works). This is an issue, because it might cause a buffer overload if the number of items to process is a significant number.
I am looking at wp-cli
and there are 3 options which may be appropriate, if at all. These are eval-file
, eval
, or wp-shell
. Also, I'm on both a Windows (dev) and a linux (prod) environment. wp-cli is not a fan of windows.
The function depends heavily on WordPress functions, and functions of the plugin classes. I could rewrite it so it's simply a script without those dependances, but I don't want to do that as it will involve maintaining a separate codebase. Also, it seems wrong.
The biggest issue right now is buffering. The function needs to flush each echo'd output, so as to not cause that overload. A correct command line process would also mean stdout
and stderr
could be directed appropriately.