Communicating to plugins from webserver

The php code at apache, and therefor wordpress, is executed only as a response to an http request, therefor you can not “wait for event” the way you try to do. You will either have to trigger the required action via http, a specifically crafted URL for example, or load wordpress from the CLI, and after it has bootstraped, execute your code. You can look at the code of wordpress CLI utility https://github.com/wp-cli/wp-cli to learn how ir can be done.