Support » Developing with WordPress » Execute ssh command after save_post hook

  • I need to execute a ssh command after publish or update a post or page in order to purge varnish. In my website I have a varnish with docker and I can’t use any plugin to purge varnish, so I have to do it manually and I want to automate this process.

    Do you know if there is some plugin for executre ssh commands in this hook?

    Thanks in advance.

    • This topic was modified 1 year, 3 months ago by Àngel Ayach.
    • This topic was modified 1 year, 3 months ago by James Huff. Reason: redundant link removed

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    On what server is the command executed? PHP can run terminal commands on the same server with exec(). However, many hosts disable this function for security reasons. If the command is to be run on another server, you could create a bash script to make the ssh connection and execute the command, but you still need exec() to start the bash script. You can call exec() if it’s available right from a callback hooked to “save_post”.

    Dion

    (@diondesigns)

    You might want to look at this:

    https://github.com/timwhitlock/php-varnish

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Execute ssh command after save_post hook’ is closed to new replies.