• Having event on the sever from SQL database updates?
    12 replies, posted
Is there anyways to get a trigger on a server (gmod) whenever an SQL database updates? (Strictly from the gmod server side). I'm creating an addon which will have multi-server support, however, I just realized if two (or more) servers are running at the same time, whatever happens on one server will update the SQL database, but the data won't update on the other server (I have it set up so that I only have to query the database once to get the information, and then store it in a table, and not have tons of queries running constantly). Do I have to rewrite the system so that the database will get queried every time it gets the information? (Which seems to me that it would be super slow.) Is there a way to write some sort of query that sends a trigger to all other servers that information has been updated? Is there a way to specify which information has been updated (deleted, created, updated, w/e)?
If you want to do it well...Use sockets, otherwise pool messages every 5 seconds, when you modify your DB, create in another table a message that when readed from the otherserver, it refreshes it data, then remove this message so it doesn't loop forever But if you want data in realtime, consider sockets
Can you go a bit more indepth in what sockets are and how they apply to gmod? Maybe link a guide I should read up on? Thanks! Also, using sockets, can I do that through Lua or would I need to create a module?
gm_bromsock
But I don't know anything about socketing and how it applies to gmod and how I would use it for my problem.
Sockets connect 2 devices through internet, you can send messages from server A to server B almost instantly, so after you modify SQL on server A, you can send a message via socket to Server B so it updates it info via sql Everything I said is theoric, there's lot of stuff behind that makes it hard, you can still do my second solution, although i can't write you code for it
Would it work for more than two? Also, I can write my own stuff for that solution, but I'm worried about lagging out the server sending queries every 5 seconds.
Both ways works well, you can pool messages in sql and delete the row after it worked well (people been using that for donations systems) Can you tell us what are you trying to solve?
Just have a job creator with a credit system. Basically just have the job update on the other servers when the player buys it on another. This is meant for more than 2 servers. I think what I'm just gonna do is have a message table in which servers will check every 5 seconds and then just have a key in that table for each row that says if the server has checked it already (or maybe a key on the server). Deleting the row wouldn't work because other servers wouldn't then be able to update as well. Again, it's not just 2 servers, it's multiple servers.
Maybe only query the database whenever someone actually requests any information about the jobs, like when someone opens the job gui or whatever? With a reasonable client<->server ping and server<->db ping the client shouldn't see any delay of more than a second or so, add a loading bar.
Yea, totally, and with 5 servers, people can just spam it. I'd be ddosing myself.
That's easily fixable by just having a cooldown on the requests, make people not able to request more often than every 5th second. Have the UI automatically request for updates. If someone requests (who have already requested once = atleast have some data) before their cooldown, deny the request and don't send back any data, make their clients use a cached copy.
Easier to just have a table with data rows of what needs to be updated, and just check that table every 5 seconds.
Sorry, you need to Log In to post a reply to this thread.