Just to clearify;
There is a very signifficant difference between JavaScript and PHP. But for starters, let me write a couple of words about the HTTP protocol (used on the WWW).
The process starts when you type in an address (URL) in your browser. I will skip the steps about DNS lookup and so on. A connection is established to the server (on port 80 if nothing else is specified). Now, if you didnt specify a document name, a default document will used (index.html, index.htm, index.php or whatever the server is set to). This file is sent directly to the browser. The connection with the server ends, and the server itself doesn't even know you were there. It has sent you the document you requested, and its job is done.
Now, if you have PHP installed on your server, a certain criteria will determine if this is a PHP file (extension .php, .php3, .phps etc). If this is the case, the file will be sent to the PHP parser, and THEN to the browser. After this, the same. Operation completed, it doesn't even know you were there.
(The browser parses the recieved HTML-code and connects to the server, or other servers, to download images and other embedded contents).
Now, in the file downloaded by the browser, wich it parses, there may be JavaScript code. If such code is present, and the browser supports it, it will be executed. At this point, there is no communication whatsoever with the web-server. JavaScript code runs locally on the browser, and PHP code only modifies what data is sent to the browser in the "initial state".
So, if you want to know when a browser window is closed, you'd have to have control over the browser, right?
The PHP engine is by long finished with its job when you close the browser (provided the page is not still rendering). There are basically three methods of transferring data from the browser to PHP; POST, GET and cookies.
The event of a closing browser can only be detected by JavaScript. You can, however, combine the two. If you trigger a browser close in javascript, you can for instance redirect to an URL and transfer data using the GET method (www.site.com/test.php?name=test&address=test).
Hope that cleared up something.