Jump to content

Getting Number of users searching for a match.

So I want to create a search match function on my website which is mostly written in php. So when the user presses a button the website chooses another user that has also clicked on the search button. I can do this using mysql and when the user clicks search it adds a row in the mysql table and the website searches from all of the rows. But how will I detect when the user left the website(closed his browser) because if I dont remove him from the search then users will be matched with no-one. So how to detect if a user has left the search(website). Also if there is another way of doing the search instead of mysql which will be better you can suggest! 

Thanks.

I like potatoes, if you don't then please just step aside and let me enjoy this potato.

Link to comment
Share on other sites

Link to post
Share on other sites

You can ping your site with ajax every x second. So when user starts searching by pressing a button, script (js) would start pinging a website every x seconds and your website would update search row with a new time, so if the time is more then x then user wouldn't be matched with anyone.

There can be of course bugs like skipping one ping, but another should update time just fine, You may want to figure out how to link row with actual person, and make it so no one other would be able to update time.

You can also read about websockets as those would be faster and less resource heavy.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×