Jump to content

info on connection_aborted()


onlyican

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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.