The event handlers interface lets you subscribe to a particular Plesk
event and trigger a particular action depending on the event
information. For example, if you need to create a DNS zone each time a
new domain is created, use event handlers.
For triggering simple actions, such as logging information about Plesk
events, we recommend that you use the event tracking mechanism available
in the Plesk UI. To learn how to use this mechanism, refer to the
Administrator’s Guide, section Event
Tracking.
For complicated actions, Plesk provides another, more flexible,
mechanism of event tracking. This mechanism allows running PHP scripts
upon Plesk events. In this section, we will explain in detail how to use
it.
How to Create a Handler
Event handlers examine the Plesk action log and invoke the
handleEvent method each time an action is added to the
log. Thus, event handler cannot prevent the action. If an attempt to
perform the action fails, Plesk does not issue notifications through
this mechanism.
Event handlers for the same event can be triggered in an arbitrary
order.
To add an event handler, create a .php
file in the following
directory:
-
On Linux:
/usr/local/psa/admin/plib/registry/EventListener
-
On Windows: <plesk_dir>
adminplibregistryEventListener
Where <plesk_dir> stands for the full path to the directory where
Plesk is installed.
This file must contain a class which implements the
handleEvent method of the EventListener
interface.
The code must create an instance of this class and return it. For
example:
<?php
class TestEventListener implements EventListener
{
public function handleEvent($objectType, $objectId, $action, $oldValues, $newValues<span class="…