Kohana Session Table - php

Currently i am hosting a website with ~10k unique visitors a day and ~6 clicks per user.
So round about 60k pageviews a day.
I use Kohana 3.2 and save the session datas from every user in the "sessions" table. Every page request execute a timestamp refresh in this table! So it's round about 60k updates (excl. Selects / Inserts / .. ) refreshing timestamps only.
The mysql process is getting pretty low..
So that's my question:
Should i stop using the SESSIONS table for saving user
How can i use the $_SESSION instead the values from the table?
Is there another alternative to handle this problem right now? We orderd more server capacity but have to wait..
EDIT:
Maybe it's enough to deny all these "updates" by every click..?

Okay. At least it was enough to truncate the table "sessions" - for the first moment. There was more than 1kk records - thats why the database operations getting pretty slow..?
Maybe it's just a simple mysql problem, and it's enough when i change it NOSQL.

Related

duplicable database

Is there a way that i can copy my database (a) from localhost and place it intro database (b) localhost?
I was thinking mb php has some manually (on refresh page opera refresh page every 1 seconds) or automatic php get from db(a) post to db (b) anything like this possible ?
What i need it for ...in to db (a) i store new members and every 30 minutes db (a) deletes itself, but db (b) its always full. So even if myweb.com gets hacked no one knows to hack myweb1.com if that makes any sense. One website hides the other
Its very hard to answer your question becouse we dont know much about your web and SQL servers.
If you have 2 SQL servers or 2 instances, or 2 separate databases you can easy create SQL JOB
and schedlue it to execute every 30 min or so.
Job would be simple to select data from DB(a) and insert them in DB(b) then delete records in DB(a) .. you need to make it in SQL transaction so new records added in DB(a) when you move records dont get deleteded

Caching location based data cluster

How to serve the search results from a particular location without querying the database again and again that holds millions of records?
We are having a database of billions of records with latitude and longitude. And it is growing every minute. And now, we need to serve those data to our mobile application. So we planned to show this in following categories.
Showing latest 10 inserted results:
For this, we are using a table in which when every new record comes, we are inserting it into the queue table and removing the last value if it is greater than 10.
Showing the latest 10 results from the user location:
For this, we need to aggregate the data and show to the local users every 5 mins and we can serve the same data to all users from that locality for 5 mins.
Now, i need help with,
How to divide the areas? For example, if i divide the world in form of squares, then i can serve same data for each square for next 5 mins. Is there any algorithms to divide the areas in similar model using geo location or do you think that any other model better suits for this?
How and where to cache the content for each area to serve only for next 5 mins, and it need to refreshed with new data. Is there any caching algorithms present in DB itself or is there any other technique present for this? For example, if we have areas A & B into 2 squares, and if a user from "A" requests a data, then we need to cache the result and need to serve with same result without querying the DB to all the users requesting for next 5 mins from the same square "A" and need to refresh it after that. So that i can save server bandwidth. But how to do this?Any server caching? Temporary tables or How?
Please direct me on this. Or if you think that there is a better approach, please, please let me know. Any references are also greatly welcome. Thanks everyone in advance.

Saving last SQL query state in PHP

For a two-player game, I need to send updated data to player every 30 seconds.
I have a table (ideally 4 tables) from where I need to select data and sent to user once he/she login. Since it is multi-player interaction game, data needs to be sync every 30-60 seconds.
My problem is, I've a very heavy query to run every 30-60 seconds. So ideally, I should send only updated and new rows to the player during sync (Its also a front end requirement for IPhone/Android game, app don't want whole data during every sync operation).
I went through MySQL: difference of two result sets and hope I'll get only updated/new records through SQL but problem is, how do I save result of last query.
Even if I save first result in Session (probably not recommended) that record will be useless as soon as new row inserted or updated. Updating session record again will definitely put lot of pressure on the server.
Can someone please suggest the best way to achieve this requirement; Not detailed solution, just some hint/link will be sufficient.
Basically, this isn't that hard. Let me provide you with a step plan.
Add a datetime field to each table you want to do this on
In each of your updating queries, set this field to NOW()
Make sure that the application adds the time of its last update to all its requests
Have the server add the time of the update to result it send to the app (which also sends the updated rows)
Can't you just timestamp everything?
Give every row in the tables a timestamp called something like "last_updated"
In the query, filter out all entries with a last_updated that is before the last time the query was executed (or possibly the latest last_updated that the client got the last time it called the server)

who's online with timestamp with high performance

i just created a user login system with php session and now users can register and login to site and do another things...
now i want to create online.php which will fetch all online users.i almost search everything in google and stackoverflow for this with no success.
ok now i want to describe the system which i want to create with high performance..
when a user logged in we just update table user.lastlogin which is a timestamp and then in online.php we SELECT * every user where time interval is < 5 minutes.
for this purpose i can update this timestamp lastlogin field in database when user load each page,and this cost many mysql query to do the job... then in each page load i have to update
UPDATE user set last=now()
that will cost me many mysql query.now i am looking for some another way like using sessions or something that i found in this link
"The normal solution is to store a timestamp in the table which you update every time the user does something. Users with a recent timestamp (say, five minutes) are shown as logged in, everybody else are logged out.
It doesn't even have to be updated on every page load. Keep a timestamp in the session with the last update time as well, and only update the table when the database flag are about to expire."
but unfortunately the answer wasnt quite helpful and i need an example or more describe on this.
1.) If you need more speed in sessions there is for example memcache. A simple key - value store to save your sessions or keys. You can configure Apache that all sessions will be automaticly stored in memcache.
2.) Another solution is to make a MEMORY Table which MySQL holds in RAM. Problem is when you restart your server the data in this table is lost. But i think in your case for last logon there is no problem.
3.) PHP Shared Memory: http://php.net/manual/de/ref.shmop.php for small data.
When you have implemented a solution i would prefer the MEMORY Table or the SHM solution.
Edit: The last paragraph with the searching on HDD was related to the comment on top: Find Number of Open Sessions

Timer based status changes that are saved to database

I have a PHP website using a MySQL database.
We have items that users create, that are on a timer, and once this timer has counted down, without user interaction (basically next time someone sees it) the status needs to have changed.
I'm not sure how to implement this in a way to be accurate to the minute.
So we have an object X, that expires at 10:15pm tommorrow, and the next person to see object X after that time has to see it as expired.
Is the correct way to do this to be the next time object X is loaded we check if it's expired, and if so, update the database?
What happens if 10 people load object X at the same time after it's expired, what's to prevent some sort of race condition from all 10 requests attempting to update the database?
Is there a cron job that runs every minute that I can some how make use of, or any type of timer in MySQL to kick off every minute checking for these and running a script?
I have several ideas on how it -could- be done, like those listed above, but I'm not sure what the most practical is, or what the standard way to do it is as I'm positive someone has solved this problem before.
Is the correct way to do this to be the next time object X is loaded we check if it's expired, and if so, update the database?
Why do you need to update the database? It seems like you might have some redundancy in your DB table - from what you've said, it sounds like you have (for instance) an is_expired column and then an expires_at column.
Why not just get rid of the is_expired column? It's cheap to compare 2 integers, so when you want to determine if something is expired, just fetch the expires_at column and compare with the current time. This avoids any race conditions with expiry, since nothing in the DB changes.
You can do it with cron of course. Or with javascript native function setInterval( "checkFunction()", 10000 ); to alter the db. Or you could use a date field in DB and check for expiration
Make a field date_to_expire as DATE , enter the expiration date and everytime you query for it check to see if the item is expired (this can go up to seconds)

Categories