Jump to content

Archived

This topic is now archived and is closed to further replies.

onlyican

info on connection_aborted()

Recommended Posts

hey

I have been coding for over 24 hours now, I needed a lil break

So, my version of a break is to research some things,
I was checking the php.net site, for functions that might be useful, or might do the same as some functions I have made

I came accross
connection_aborted();

Theres not much information on this

The only info it says is
"Will return true if the clients has disconnected"

Does that mean, I can use this to check if a logged in user has disconnected
Meaning I can log them out

Is the Disconnected from Closing the Window or something else?

http://www.php.net/manual/en/function.connection-aborted.php
Anyone know anything about this function?

Share this post


Link to post
Share on other sites
[url=http://www.php.net/manual/en/features.connection-handling.php]This[/url] has more indepth info on what it is used for.

Share this post


Link to post
Share on other sites
It's not used often because there isn't many scenarios to use it in.

PHP won't suddenly wake up and do something when the user disconnects, that function can only be used with in the process of a very long, or infinite loop, and that's it.

As the (not very good) example shows from the user notes on the php page:

[code]<?php

while (!connection_aborted()) {
   echo "New line!<br />\n";
   flush();
}

?>[/code]

Because of the way PHP works with it's output buffer, you have to invoke the flush() function else the user will not see any output until all operations have ceased. (Which they won't see because the only way to cease the operation is to disconnect..)

This function is primarily to allow developers to cut down on the amount of resources used by PHP on some operations. Other wise the above would infinitley loop hogging all your servers resources.

Share this post


Link to post
Share on other sites
ok cheers

I thought it would run a script when the user closes a window.
I was thinking excellent way of logging users out, to check who is online

I stick to my old way

Cheers hombres (and ladies if any)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.