如何在cakephp中重新加载页面之前触发事件,或者只是普通的php跨平台兼容方法?

I am trying to trigger an event before a controller the action is called and even before the _construc function for that class is called.

I tried using cakephp beforeFilter, initialize and _construct method, didn't work as expected and i tried javascript code to trigger an event before the page is refreshed or reloads, but not working as expected. Here is the code i tried.

$(window).on('beforeLoad unload',function(){
$.get('http://www.antlax.com/provider/terminate');
});

I am expecting to terminate a process before the page is reloaded, so that at any giving time, there will be only one process for that page for all clients connected to the server.