[PHP] Re: synchronizing php functions

2002-07-03 Thread Philip MacIver

Well I have a system that people can login to, and I want to produce an array (or 
something of the sort)
that holds who is logged in so that I can monitor it. The problem is that sessions are 
local to the clients machine
so if I tried to put this information in the session then the only information that I 
would get back is the people that
are 
logged in on my machine, not the server (Please tell me if I wrong in what I say 
here). Therefore I need to be able to
but this
information in the session and have it available to all sessions (sort of like the way 
static variables in Java belong
to the class and 
not the individual objects that are created from that class). So if you undersatnd 
what I'm trying to do here and know
of a way
to do it I would love to here it.


On Tue, 02 Jul 2002 18:45:40 -0500
[EMAIL PROTECTED] (Richard Lynch) wrote:

 Does anyone know anyway to synchronize calls to php functions.
 I was thinking of writting a hack that uses a lock file on the server put 
 if there is a proper way to do it then I would
 rather use that.
 Any suggestions would be good.
 
 Shared memory may be faster than lock files...
 
 *WHY* you think you need synched PHP functions might be an interesting
 discussion, though if it's just for fun, have at it.
 
 -- 
 Like Music?  http://l-i-e.com/artists.htm
 


|---|
   Philip MacIver
|---|  
|  
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: synchronizing php functions

2002-07-03 Thread Erik Price


On Wednesday, July 3, 2002, at 04:08  AM, Philip MacIver wrote:

 The problem is that sessions are local to the clients machine

Huh?

 so if I tried to put this information in the session then the only 
 information that I would get back is the people that
 are
 logged in on my machine, not the server (Please tell me if I wrong in 
 what I say here). Therefore I need to be able to
 but this
 information in the session and have it available to all sessions (sort 
 of like the way static variables in Java belong
 to the class and
 not the individual objects that are created from that class). So if you 
 undersatnd what I'm trying to do here and know
 of a way
 to do it I would love to here it.

This has been discussed on the list before, and even I think just last 
week (so check the archives, using server variables asp as your search 
criteria).  Some theories suggest that it would entail a lot of 
overhead, unless you only have a few users to keep track of 
simultaneously.  Possible suggestions are

1) if the data doesn't change, put it into an includefile
2) if the data is dynamic, be clever and implement this yourself with 
database-managed persistence (but beware the overhead).

Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: synchronizing php functions

2002-07-03 Thread Richard Lynch

Well I have a system that people can login to, and I want to produce an 
array (or something of the sort)
that holds who is logged in so that I can monitor it.

Aha!

The who's logged in right now feature!  :-)

Problem #1.
First, you need to clearly define logged in

Am I logged in for the less than 2 (hopefully!) seconds that it takes me to
download a single HTTP page, or am I logged in until I log out or am I
logged in until I don't do nothing for N minutes, and then I'm
auto-logged-out, or some combination.

Because logged in has *NO* real meaning in an HTTP connection, unless you
want to strictly show who's using each HTTP connection at this 2-second
instance in time...

 The problem is that 
sessions are local to the clients machine

No, no, no.

PHP session data all lives on the server, except for the cookie ID on their
local machine, and you can even avoid the cookie ID if you want to use the
SID in every URL/ACTION/POST/GET HTTP connection.

so if I tried to put this information in the session then the only 
information that I would get back is the people that
are 
logged in on my machine, not the server (Please tell me if I wrong in what 
I say here).

Either I'm not understanding what you want, or you're *WAY* off target...

If you want to know who is LOGGED IN to telnet/SSH on your WEB server, you'd
want to do like:

?php `who`; # Is it called 'who' ?  Whatever Un*x command tells you who's
logged on.?

If you want the web-server to know who is LOGGED ON to your desktop, there's
no way PHP can do that.  Big, big, big security issue on that one...

Now, maybe, if you had a Java applet and you authorized it to run and it
sucked in who was logged in to your desktop and sent that back to a Java
servelet, you could do that...

Dunno who would want that or why, nor who would trust the applet enough to
run it in the first place, but I think you *could* do that...

If you want to know who's surfing your web-site now, then you need to
better define what now means, and read the other parts of this post.

 Therefore I need to be able to
but this
information in the session and have it available to all sessions (sort of 
like the way static variables in Java belong
to the class and 
not the individual objects that are created from that class). So if you 
undersatnd what I'm trying to do here and know
of a way
to do it I would love to here it.

Easiest way to do this:

First, alter your user login/management table so that there is an 'activity'
datetime field.

Next, include something like this file on every page:

?php
  $query = update users set activity = now() where user_id = $user_id;
  mysql_query($query) or error_log(mysql_error());
?

To see who's logged on, just do:

?php
  $query = select username from users where activity + 5*60 = now();
  $current = mysql_query($query) or error_log(mysql_error());
  while (list($username) = mysql_fetch_row($current)){
echo $usernameBR\n;
  }
?

5*60 is 5 minutes.  (60 seconds per minute)  Change that to whatever you
like.

-- 
Like Music?  http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: synchronizing php functions

2002-07-02 Thread Richard Lynch

Does anyone know anyway to synchronize calls to php functions.
I was thinking of writting a hack that uses a lock file on the server put 
if there is a proper way to do it then I would
rather use that.
Any suggestions would be good.

Shared memory may be faster than lock files...

*WHY* you think you need synched PHP functions might be an interesting
discussion, though if it's just for fun, have at it.

-- 
Like Music?  http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php