0

I am hoping someone can explain how to do this to a laymen like me. I found a work around posted by someone else for a project I'm working on. However, I'm not sure how I do this.

Here is the workaround posted by someone else:

I found a way to get around this when using a browser other than the default: I simply make a call via ajax to a PHP function which contains the following code:

<?php
shell_exec('taskkill /T /F /IM "Server2Go.exe"');
?>

This ends the task tree for Server2Go which kills the Server2Go.exe file, Apache and MySql.

So I created the PHP file containing the code he/she wrote. How do I create an AJAX call that would recognize the browser has closed and kills the "Server2Go.exe" process? And once it is created, where exactly to I place it? I searched on Google and found several ways to "make an ajax call" - but wasn't sure exactly where I needed to place it.

That is my question, so you don't have to continue, but In case other info is wanted: I am currently running a local wordpress install with Server2Go - Which launches apache, mysql, and basically everything you need to have a server and database for a local install.

It also has a feature to shutdown the "server2go.exe" process as well as all the child processes. It is designed to work with IE, but I prefer to use another browser. Because I use a different browser it does not shutdown the "server2go.exe" process.

Wes
  • 3
  • 1
  • 3

1 Answers1

0

You can use the jQuery script below to identify a browser/tab close event and then make an ajax call to your php.

<html>
    <head>
        <!-- Load jQuery Libraby -->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script>
            // Bind the window before load event.
            $(window).bind("beforeunload", function () {
                // This code is running when user refresh the page or tab is clossin or browser is closing.
                $.ajax({
                    type: "POST",
                    url: "the php url"
                }).done(function (response) {});
            });
        </script>
    </head>
    <body>
        <!-- Whatever the body of your page will include -->
    </body>
</html>
Georgios Syngouroglou
  • 18,813
  • 9
  • 90
  • 92
  • I have tried this code by placing it in the index.php of server2go install.. I haven't noticed a difference. Is there a certain place I am supposed to place it? – Wes Mar 18 '14 at 02:22
  • I updated the code. This is the simplest html to identify a browser close or refresh or a tab close. You have to replace the text "the php url" with the url to your php (you have to run your php inside of a server). – Georgios Syngouroglou Mar 19 '14 at 20:03