Execute php after post save/update

I believe you should look into status transitions: https://developer.wordpress.org/reference/hooks/transition_post_status/

There are a couple of examples below the explanation on top of the page. Here’s also some example code of mine:

add_action( 'transition_post_status', 'nxt_create_news', 10, 3 );
// Automatically create a news when a wiki post has been published
function nxt_create_news($new_status, $old_status, $nxt_wiki_post) {
    if('publish' === $new_status && 'publish' !== $old_status && $nxt_wiki_post->post_type === 'wiki') {
... do something here
}

In your case, the old_status should be ‘publish’ and the new status as well. Make sure to find a way to prevent an endless loop, but I believe that the examples on the WP documentary should prove useful. 🙂