Bitcoin Forum
April 25, 2024, 04:13:12 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Web language question  (Read 994 times)
FreeMoney (OP)
Legendary
*
Offline Offline

Activity: 1246
Merit: 1014


Strength in numbers


View Profile WWW
November 24, 2011, 11:19:17 AM
 #1

Trying to figure if javascript and php is good enough for an idea I have, and if not, what language(s) I need.

A player clicks something which modifies the database, immediately the values from the database that were showing on the page are updated, no page refresh needed.

Another player who is currently viewing the same values on their page also needs to be instantly updated.

What is it best and will scale well? Database of ~10k players, several hundred logged in, ~50 columns if any of that matters.

And what about handling a "who pressed first" scenario? I don't really care if it is super accurate, just that it can pick one winner. I think this part is trivial, just want verification.

Didn't want to bog down with details, let me know if more is needed.

Play Bitcoin Poker at sealswithclubs.eu. We're active and open to everyone.
"Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714018392
Hero Member
*
Offline Offline

Posts: 1714018392

View Profile Personal Message (Offline)

Ignore
1714018392
Reply with quote  #2

1714018392
Report to moderator
1714018392
Hero Member
*
Offline Offline

Posts: 1714018392

View Profile Personal Message (Offline)

Ignore
1714018392
Reply with quote  #2

1714018392
Report to moderator
dogisland
Sr. Member
****
Offline Offline

Activity: 262
Merit: 250



View Profile
November 24, 2011, 06:34:10 PM
 #2

You could do this with PHP and Javascript.

Have a look at JQuery if you haven't already and the Ajax and timer methods.

ineededausername
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1000


bitcoin hundred-aire


View Profile
November 24, 2011, 06:39:04 PM
 #3

Update procedure: user data -> jQuery -> update.php -> DB -> immediate update by jQuery -> user view
For everyone else: user <- jQuery timer request <- view.php <- DB

(BFL)^2 < 0
netrin
Sr. Member
****
Offline Offline

Activity: 322
Merit: 251


FirstBits: 168Bc


View Profile
November 24, 2011, 07:20:11 PM
 #4

Is this really about languages or databases? Have you looked into Redis? Atomic, fast as lightning. At least when I shard'd 200K transactions per second for a project 9 months ago.

Greenlandic tupilak. Hand carved, traditional cursed bone figures. Sorry, polar bear, walrus and human remains not available for export.
btc_artist
Full Member
***
Offline Offline

Activity: 154
Merit: 101

Bitcoin!


View Profile WWW
November 24, 2011, 07:28:23 PM
 #5

Trying to figure if javascript and php is good enough for an idea I have, and if not, what language(s) I need.

A player clicks something which modifies the database, immediately the values from the database that were showing on the page are updated, no page refresh needed.

Another player who is currently viewing the same values on their page also needs to be instantly updated.

What is it best and will scale well? Database of ~10k players, several hundred logged in, ~50 columns if any of that matters.

And what about handling a "who pressed first" scenario? I don't really care if it is super accurate, just that it can pick one winner. I think this part is trivial, just want verification.

Didn't want to bog down with details, let me know if more is needed.
You can easily do all of that with Javascript to make an AJAX call to the back end PHP script to update the database.  The who pressed first scenario is easy in that the first one to update the database wins.  The only iffy part is updating all other players' pages.

Another player who is currently viewing the same values on their page also needs to be instantly updated.
Being stateless, the HTTP can't handle push notifications from server to client.  The way this is typically handled in Javascript is to set a timeout and poll the server for updated values at a given interval.  If things don't have to be instantaneous, this works well.  If you want instant or near instant updates, then you would have to poll the server for updated information every second or every 500 ms or so.  If you have lots of online users, this can be a bottleneck unless you beef up your web server and database server to handle all the poll requests.

BTC: 1CDCLDBHbAzHyYUkk1wYHPYmrtDZNhk8zf
LTC: LMS7SqZJnqzxo76iDSEua33WCyYZdjaQoE
netrin
Sr. Member
****
Offline Offline

Activity: 322
Merit: 251


FirstBits: 168Bc


View Profile
November 24, 2011, 07:34:11 PM
 #6

I mention Redis because it takes very simple HTTP REST requests, all single threaded-atomic, and I don't believe there is anything faster. Clients could easily poll the redis servers. Read-only replicated Redis slaves could reduce the burden of the write-master instance, but I doubt you'd need that with only 10K clients. If you don't need server side logic, why introduce an unnecessary bottleneck? -- unless you don't trust the clients.

Greenlandic tupilak. Hand carved, traditional cursed bone figures. Sorry, polar bear, walrus and human remains not available for export.
eleuthria
Legendary
*
Offline Offline

Activity: 1750
Merit: 1007



View Profile
November 27, 2011, 07:18:15 AM
 #7

If you want live updating for OTHER users, this can be accomplished using long polling (yes, just like Bitcoin Mining).  I've done it before for a web RPG where it had a true live chat and map where players walked around (scrolling like classic console RPGs).

There's two ways to pull it off without newer technologies like web sockets:

1) Bitcoin style longpolling, where an AJAX request is directed to longpoll.php .  This is a looping PHP script (or if you want higher efficiency, a custom made TCP socket program that responds with HTTP formatted responses), that consistently checks for a modified variable.  You could do this either with a file on the webserver that simply stores an incrementing counter each time something changes, or a temporary table in your database that increments a counter on each change.

When the counter increments, the AJAX query complete, and you set your response function to issue a new request for the updated page, and then initialize a new long poll connection.

2) A bit trickier, this involves the same looping script/TCP socket program.  However, instead of firing off a simple "data updated" response and then having your javascript issue a new request, it streams the response back.  The hard part in this is the way different browsers handle XmlHttpRequest objects when the response is only partial.  For firefox I believe it required 1 kB of data sent back before it would allow you to reference the current response text.  In internet explorer, its even more difficult and requires some very ugly "virtual iframes" (invisible iframe objects that aren't actually a part of the page document).  Your PHP script will have to force output as its ready for parsing using ob_start/ob_flush, etc.

The advantage to this method is you achieve a true "live" system other than the minor sleep at the end of the PHP loop, which can be as low or high as you want depending on server specs.



For the 'who pressed first' scenario, obviously it's just a matter of forcing a timestamp being posted as part of the script that executes when a button is pressed.  The server generates/stores the timestamp, so there is no way for a tie/modified timestamp.


Since you're only talking about a few hundred online simultaneously, you're not going to run into too many problems unless you're in a shared hosting or budget VPS provider scenario.

RIP BTC Guild, April 2011 - June 2015
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!