One possible approach would be as follows:
Configure all "slave" Pis to allow login from the "master" (pi running apache) via ssh with public/private keys.
Have apache run a script something like this:
I don't know apache, nor which program language you're using to be more specific. Sorry.