Jump to content


Photo

info on connection_aborted()


  • Please log in to reply
3 replies to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 29 August 2006 - 12:57 PM

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/m...ion-aborted.php
Anyone know anything about this function?

Tell me the problem, I will try tell you the solution

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 August 2006 - 01:05 PM

This has more indepth info on what it is used for.

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 29 August 2006 - 01:13 PM

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:

<?php

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

?>

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.

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 29 August 2006 - 01:40 PM

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)
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users