0

Is there another way for me to run a WP-CLI command from within a PHP script other than using the shell_exec() function.

2
  • What command are you trying to run?
    – Caleb
    Jul 11, 2023 at 17:52
  • I'm trying to run a custom command which contains a wp-cli script that I created. The script needs to run as a cron job and it needs to run server side as if it doesn't it will time out and it will cause the initial page load on the cron run to be very slow (due to the way that WordPress manages cron jobs).
    – TKEz
    Jul 12, 2023 at 18:11

1 Answer 1

0

If it's a script you created, then move the function outside of WP CLI, where both WP CLI and your PHP script can access, and then have your WP CLI command run that function.

1
  • I like where this is going. However, it's a php function that is run on a scheduled WordPress cron event that runs a WP-CLI command and it must be run via WP-CLI because it uses native WordPress functions.
    – TKEz
    Jul 13, 2023 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.