Documentation / Tutorials / Awesome Enterprise

Execute service asynchronously via WP-CLI

/ Awesome Enterprise / Execute service asynchronously via WP-CLI

Sometimes we have long running process which needs to be run without any time limit.
also this execution should be done asynchronously.
to achieve  this many developers use to run PHP file via Command Line.

Same phenomenon is used here.

To execute the Shortcodes via CLI, I used the WP-CLI tool of WordPress.

Run service via CLI:

[ servicename.module.template param='paramval' /]

This shortcode will run the service “servicename.module.template” asynchronously and return the OS process id of the execution.

note: for this shortcode all parameters should be only in string format don’t pass the array as the parameter.

View particular process status:

to view the particular process id information use this shortcode

[awcli.isrunning pid='123' set=template.res /]

View all process status

To view all process information use this shortcode

[awcli.allrunning set=template.allpids /]

Above shortcode will return the array of current running processes.
for best practice use this array to show the process queue in the dashboard to know the statuses of all running processes.

kill particular process

to kill the unwanted service use bellow shortcode

[awcli.killpid pid='123' /]

note: you can only kill the processes which are created via www-data user

warning : executed via WP-CLI so PHP never time out, that’s why always make sure your code will be terminated properly or don’t overuse the memory because this may cause server down.


All above functionality will be available from AE version or above.

Most Popular

Leave a Reply

Your email address will not be published.