Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-25-2019, 06:44 AM   #1
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 49,080
Question for Programmers: What's a good way to see if a browser connection to a server is active?

What's a good way to check browser connection with server to see if its still active?

For example: Let's say you have a bunch of people connected to a page on your website, and you want to know in real time or near real time, who by username is connected, and when they click away.

Suggestions appreciated!
__________________

Custom Coding | Videochat Solutions | Age Verification | IT Help & Support
www.2Much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 07:05 AM   #2
klinton
So Fucking Banned
 
Industry Role:
Join Date: Apr 2003
Location: online
Posts: 8,766
if its wordpress, there are plugins for that...
klinton is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 07:44 AM   #3
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 49,080
Quote:
Originally Posted by klinton View Post
if its wordpress, there are plugins for that...
No, but they could be useful too. Do you know what they are called? Links if you have them..!
__________________

Custom Coding | Videochat Solutions | Age Verification | IT Help & Support
www.2Much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 09:30 AM   #4
zerovic
Confirmed User
 
zerovic's Avatar
 
Industry Role:
Join Date: Apr 2010
Posts: 1,101
You can use ajax for that... simply fire it every, let's say 5 seconds and call a PHP script with it that will update the users last online time / date... with this, you'll see who's "last_online" time/date was updated recently, which means they were online in the last 5 seconds...
zerovic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 10:05 AM   #5
CurrentlySober
Too lazy to wipe my ass
 
CurrentlySober's Avatar
 
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,614
Years ago, in about 02/03 I was shown a website stats thing that showed all the users on your site, in real time, and what they were doing etc... But it wasn't just 'dry' text. It was actual animated little people, and the pages of the site were represented as rooms in the building and as someone moved from page to page / room to room, so did the little animated figure on screen.

A bit like very early sims but for website. Dunno what it was called, but it was pretty expensive apparently
__________________


👁️ 👍️ 💩
CurrentlySober is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 11:45 AM   #6
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 49,080
Quote:
Originally Posted by zerovic View Post
You can use ajax for that... simply fire it every, let's say 5 seconds and call a PHP script with it that will update the users last online time / date... with this, you'll see who's "last_online" time/date was updated recently, which means they were online in the last 5 seconds...
Can you tell me more about this? Do you mean having a script in Ajax that pings the server to tell it its connected, then write it to a DB?

Quote:
Originally Posted by CurrentlySober View Post
Years ago, in about 02/03 I was shown a website stats thing that showed all the users on your site, in real time, and what they were doing etc... But it wasn't just 'dry' text. It was actual animated little people, and the pages of the site were represented as rooms in the building and as someone moved from page to page / room to room, so did the little animated figure on screen.

A bit like very early sims but for website. Dunno what it was called, but it was pretty expensive apparently
I seem to remember that too.. it was some kind of stats program but not quite what I was looking for.
__________________

Custom Coding | Videochat Solutions | Age Verification | IT Help & Support
www.2Much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 11:59 AM   #7
CurrentlySober
Too lazy to wipe my ass
 
CurrentlySober's Avatar
 
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,614
Quote:
Originally Posted by 2MuchMark View Post
I seem to remember that too.. it was some kind of stats program but not quite what I was looking for.
Yeah, I know... It just got me thinking of it as a cool little story
__________________


👁️ 👍️ 💩
CurrentlySober is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 12:41 PM   #8
zerovic
Confirmed User
 
zerovic's Avatar
 
Industry Role:
Join Date: Apr 2010
Posts: 1,101
Quote:
Originally Posted by 2MuchMark View Post
Can you tell me more about this? Do you mean having a script in Ajax that pings the server to tell it its connected, then write it to a DB?
Here's something I just wrote real fast... it's not the best solution, however, it'll do the job and you'll get the idea ;)

Code:
<?php
//make sure you are connected to your database!
if(isset($_GET['username'])) {
	$username = $_GET['username'];
	$current_date = date('Y-m-d H:i:s');
	//update the database with the current date/time
	//for example
	//mysql_query("update `users` set `last_seen` = '$current_date' where `username` = '$username'");
}
?>
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
	<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script>
	$(document).ready(function() {	
		var username = 'username';
		UpdateUserTime = setInterval(function() {
			$.ajax({
				url: "http://localhost/2MuchMark.php?username=" + username,
				cache: false,
				success: function (html) {
					$('#foo').append('User time/date updated.<br />'); // you can leave this empty, it's just to see if the request was successful.
				}
			});
		}, 5000); // the interval you want to update the current time / date.
	});
</script>
</head>
<body>
<div id="foo"></div>
</body>
Basically, you have the current username stored as a jquery variable which is sent to the php script every 5 seconds which updates the users last seen time / date.

Let me know if it works for you, or you have any questions.

ps. you are not limited to only date/time. you can store anything such as the current page if you want. for this I'd suggest using POST instead of GET, but everything is the same.

Simply change the type of the request to POST and define the data you are sending with.
Code:
UpdateUserTime = setInterval(function() {
			$.ajax({
				type: "POST",
				data: 'username=' + user + '&current_page=' + current_page,
				url: "http://localhost/2MuchMark.php",
				cache: false,
				success: function (html) {
					$('#foo').append('User time/date updated.<br />'); // you can leave this empty, it's just to see if the request was successful.
				}
			});
		}, 5000);
Cheers,
z
zerovic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 12:59 PM   #9
Sarn
KeepYourPimpHandStrong
 
Sarn's Avatar
 
Industry Role:
Join Date: Sep 2015
Location: Russia
Posts: 11,465
Quote:
Originally Posted by 2MuchMark View Post
What's a good way to check browser connection with server to see if its still active?

For example: Let's say you have a bunch of people connected to a page on your website, and you want to know in real time or near real time, who by username is connected, and when they click away.

Suggestions appreciated!
Google Analytics Real Time report.

Sarn is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 05:25 PM   #10
Colmike9
(>^_^)b
 
Colmike9's Avatar
 
Industry Role:
Join Date: Dec 2011
Posts: 7,223
If you use html5 Websocket with node.js instead of most other methods, you'll use much less bandwidth. Like a difference from xxMbps to xxxKbps for large traffic..
Colmike9 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-25-2019, 05:30 PM   #11
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 49,080
Quote:
Originally Posted by zerovic View Post
Here's something I just wrote real fast... it's not the best solution, however, it'll do the job and you'll get the idea ;)

Code:
<?php
//make sure you are connected to your database!
if(isset($_GET['username'])) {
	$username = $_GET['username'];
	$current_date = date('Y-m-d H:i:s');
	//update the database with the current date/time
	//for example
	//mysql_query("update `users` set `last_seen` = '$current_date' where `username` = '$username'");
}
?>
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
	<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script>
	$(document).ready(function() {	
		var username = 'username';
		UpdateUserTime = setInterval(function() {
			$.ajax({
				url: "http://localhost/2MuchMark.php?username=" + username,
				cache: false,
				success: function (html) {
					$('#foo').append('User time/date updated.<br />'); // you can leave this empty, it's just to see if the request was successful.
				}
			});
		}, 5000); // the interval you want to update the current time / date.
	});
</script>
</head>
<body>
<div id="foo"></div>
</body>
Basically, you have the current username stored as a jquery variable which is sent to the php script every 5 seconds which updates the users last seen time / date.

Let me know if it works for you, or you have any questions.

ps. you are not limited to only date/time. you can store anything such as the current page if you want. for this I'd suggest using POST instead of GET, but everything is the same.

Simply change the type of the request to POST and define the data you are sending with.
Code:
UpdateUserTime = setInterval(function() {
			$.ajax({
				type: "POST",
				data: 'username=' + user + '&current_page=' + current_page,
				url: "http://localhost/2MuchMark.php",
				cache: false,
				success: function (html) {
					$('#foo').append('User time/date updated.<br />'); // you can leave this empty, it's just to see if the request was successful.
				}
			});
		}, 5000);
Cheers,
z
Thanks! Will try that.

Quote:
Originally Posted by Sarn View Post
Google Analytics Real Time report.

Thanks Sarn but that's not what I'm looking for. What I want is for my own program to know which users are actually logged-in in real time, and when they click out of the site. But thanks though I appreciate the suggestion.
__________________

Custom Coding | Videochat Solutions | Age Verification | IT Help & Support
www.2Much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-26-2019, 10:58 AM   #12
NatalieMojoHost
Confirmed User
 
NatalieMojoHost's Avatar
 
Industry Role:
Join Date: Aug 2013
Posts: 1,474
Ajax is a good solution if there are no load issues.

One caveat I'd point out there is that UPDATE queries tend to be quite heavy on a database, especially if you're dealing with hundreds of users online at any time, or updating on a large table. If the information does not need to be persistent, I would update something like a memcached key or redis object for each user, as those are much less intensive than running updates in SQL. Redis could be configured to save the changes to disk every X writes/minutes for some amount of persistence as well (though not as reliably as SQL, and then that's another database service you need to maintain/backup/etc) - just something to consider.
If it is a busy site, I think it would be better to use websockets for this kind of thing, and Redis to persist data.
__________________

MojoHost.COM | natalie at mojohost dot com | Skype natalie.ac | Telegram @znatalie. Since 1999: 70 Adult Industry awards for Best Hosting Company and professional excellence.
NatalieMojoHost is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-26-2019, 01:33 PM   #13
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 49,080
Quote:
Originally Posted by NatalieMojoHost View Post
Ajax is a good solution if there are no load issues.

One caveat I'd point out there is that UPDATE queries tend to be quite heavy on a database, especially if you're dealing with hundreds of users online at any time, or updating on a large table. If the information does not need to be persistent, I would update something like a memcached key or redis object for each user, as those are much less intensive than running updates in SQL. Redis could be configured to save the changes to disk every X writes/minutes for some amount of persistence as well (though not as reliably as SQL, and then that's another database service you need to maintain/backup/etc) - just something to consider.
If it is a busy site, I think it would be better to use websockets for this kind of thing, and Redis to persist data.
Thanks Natalie!
__________________

Custom Coding | Videochat Solutions | Age Verification | IT Help & Support
www.2Much.net
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-27-2019, 05:17 AM   #14
NatalieMojoHost
Confirmed User
 
NatalieMojoHost's Avatar
 
Industry Role:
Join Date: Aug 2013
Posts: 1,474
Quote:
Originally Posted by 2MuchMark View Post
Thanks Natalie!
Hope it helps!
__________________

MojoHost.COM | natalie at mojohost dot com | Skype natalie.ac | Telegram @znatalie. Since 1999: 70 Adult Industry awards for Best Hosting Company and professional excellence.
NatalieMojoHost is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2019, 07:44 AM   #15
zerovic
Confirmed User
 
zerovic's Avatar
 
Industry Role:
Join Date: Apr 2010
Posts: 1,101
Quote:
Originally Posted by NatalieMojoHost View Post
Ajax is a good solution if there are no load issues.

One caveat I'd point out there is that UPDATE queries tend to be quite heavy on a database, especially if you're dealing with hundreds of users online at any time, or updating on a large table. If the information does not need to be persistent, I would update something like a memcached key or redis object for each user, as those are much less intensive than running updates in SQL. Redis could be configured to save the changes to disk every X writes/minutes for some amount of persistence as well (though not as reliably as SQL, and then that's another database service you need to maintain/backup/etc) - just something to consider.
If it is a busy site, I think it would be better to use websockets for this kind of thing, and Redis to persist data.
That's true, however, if you use proper indexing in the database it can work out pretty good. For instance, I have a cam model site with over 340k models and one single query took me about 60+ seconds before indexing.. once the database was indexed properly, the queries are done withing 1 second.. but true, if there are 1000+ users online, the database may crash..
zerovic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2019, 09:30 AM   #16
Kittens
👏 REVOLUTIONARY 👏
 
Kittens's Avatar
 
Industry Role:
Join Date: Jan 2016
Posts: 1,440
Use websockets.
__________________
Kittens is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-01-2019, 10:45 AM   #17
wankawonk
Confirmed User
 
Industry Role:
Join Date: Aug 2015
Posts: 1,018
Quote:
Originally Posted by 2MuchMark View Post
What's a good way to check browser connection with server to see if its still active?

For example: Let's say you have a bunch of people connected to a page on your website, and you want to know in real time or near real time, who by username is connected, and when they click away.

Suggestions appreciated!
TL;DR: Use ajax polling unless you need your server to send real-time updates to browsers. If you need to send real-time updates to browsers, use websockets.

First: The browser connection with your server closes the moment the HTTP request is completed. When you load a web page, as soon as the page is loaded, your connection with the server is closed. Nitpicky distinction, but it's important to understand it.

Now, for your use case, there's two solutions, both of which have already been suggested: Ajax polling and websockets. Here's a high-level breakdown.

Ajax polling doesn't keep a connection open with your server. It's just a little setTimeout loop that creates a NEW connection (ajax request) with your server every couple seconds. Your server can only communicate with users during the ajax request.

Websockets keep an actual TCP connection open with your server. Data can flow both ways, continuously and freely. Your server can communicate with users whenever it wants.

The big difference here is that, with ajax polling, your server can only communicate with the browser in its responses to each ajax request. With websockets, the server can communicate with the browser at any time. Think about a chat room: with websockets, the server can send chat messages to all users the moment the messages arrive. With ajax polling, the server can't send messages to users until the users make their ajax request (at which point the server sends the messages in the response to the ajax request)

Ajax polling is compatible with (basically) all browsers and any server. Websockets are not supported in older browsers, and require an async server like nodejs or tornado. Ajax polling is much easier to implement than websockets (websockets aren't really that difficult, but it's not exactly trivial to get them communicating with your server properly)

Based on the use case you've described, I would use ajax polling. Your server doesn't need to send notifications/updates to users in a continuous, real-time fashion. You just need browsers to tell your server if the page is still open.

So, IMO, stay away from websockets for this. Unless there is part of your use case that you haven't stated here, that involves the server needing to send real-time updates to users. If your server needs to send updates to users, but it doesn't need to be real time (for example, maybe a 3-second delay is acceptable), ajax polling will be adequate.

Also, as was suggested in this thread: when you store this information, avoid disk writes. If you have a thousand users on your site, all making ajax requests every couple seconds, you would be generating hundreds of disk writes per second. Not good. The information you're collecting from browsers here, it needs to be stored in memory and written to disk later, in batches.

Good luck.
wankawonk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
active, server, time, real, connected, check, connection, browser, suggestions, appreciated, click, programmers, username, website, bunch, people, question, page



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.