Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm developing a forum and I need to count the number of online persons.
According to old questions which are related to it, they says the count() function should be used.
But the count() function counts just specific user's session variables.
I mean in codeigniter, count($_SESSION['user']) gives number 2 and this number points to $_SESSION['user']['name'] and $_SESSION['user']['group'].
So every user sees number 2 in their screen as online person number. But I need to number of allocated $_SESSION['user'] variable in the server, not number of specific session variable's sub variables. What is the solution? How can I detect number of online persons?
In this case, you want to have a database, preferably MySQL and update the users table with CURRENT_TIMESTAMP() whenever the user reloads the page or does anything on the site.
Afterwards, if you want to obtain current users online, you can do
SELECT COUNT(*) FROM users WHERE last_activity > NOW() - INTERVAL 5 MINUTE;
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am working on a school project. The assignment is to recreate our own version of Ebay. A requirement is to display the number of logged in users. What is the best way to do this? We are using PHP.
We are using a database so we could save the amount of loggins there but there is no proper way to decrease this amount since people often just leave the site without logging out.
Some suggestions would be awesome!
you could have a heartbeat script that updates a datetime on the user column.
and the show logged in users script could get all logged in users with time < 5 mins
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hey so i need a way to remove a row that is connected to a user after a dynamic time. Eg: Insert that your doing something for 15 minutes, after that 15 minutes i want to delete that row automatically.
There will be lots of rows (users doing stuff) in the database and i need them to all be removed after a custom time for each that is set by the user.
How would i go about this!
Thanks in advannce
You will need 2 things.
a self_destruct_at or equivalent field that is a datetime. That will be set on creating the record.
a worker process to go through ever X minutes (probably 1) and delete the comments that are older than the current time and the created_at + self_destruct_at time
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm building a php web app that requires to create an invoice, where its ID must be incremented (e.g: 15235, 15236, 15237,...etc). It all works fine with 1 user creating the invoice. The the issue arise when there are more than 1 users hitting the create button at the same time. Supposedly the next incremented ID is 15230, and having 3 users hitting the create button the same time, the app will return 15232 to all 3 users.
FYI, I store the last used ID in a database and increment it when users create an invoice.
Does anyone has any solution? Your suggestion is much appreciated.
Simply use built-in mechanics and define ID field as AUTO_INCREMENT.
You can read more about that here.
After that just skip ID in your INSERT queries and database will take care about that for you.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've my application built on Laravel 4.1. In my application I want to get number of authentic users currently watching a particular page, like if the application has page1, page2. I want to know the number of users currently on page 1 vs. on page 2.
How can I implement this feature in laravel?
This is a very unique problem and there is not a straight solution to this anyway.
$users = count(glob(session_save_path() . '/*'));
Note that this just counts session files. It will undoubtedly contain stale/dead sessions that haven't been garbage collected yet.
A better way according to me would be if you create time stamps for each of your page and have every page issue and ajax call to the server every few seconds to update these timestamps.
So if a user is on a particular page, the page will keep sending requests to the server every few seconds and the time stamps will be updated.
You can then calculate the number of users on a particular page by querying the time stamps for the last minute or something.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Consider this URL http://twitter.com/#!/sravfeyn/status/114003158891634689 , why is the query integer so long, if it's a primary key in MySQL data table, and can be started from zero and be auto-incremented? Why should one implement his/her website's queries cryptic like this?Any security reasons?
It's not for security reasons, it's because there are so many tweets that using an auto increment ID field has reached it's maximum unsigned integer length and may crash some apps built for twitter.
The status ID's are now made up of timestamp and other details.
http://techcrunch.com/2009/06/12/all-hell-may-break-loose-on-twitter-in-2-hours/
http://engineering.twitter.com/2010/06/announcing-snowflake.html
There is no lengthening of the number; it is the actual post number. Twitter has millions of post a days so this isn't much of a surprise,.
As you can see, there are also double-digit posts on twitter. I think this is the first one.