• Advertisement
Sign in to follow this  

[web] PHP telling client he should update itself

This topic is 3512 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there! I would like to write simple 2-player card game using PHP, javascript and Ajax. It should be very responsive without player hitting refresh button all the time. For this I would need somehow to send client info that there is something new for him (e.g. oponent made his move etc...) so he should update accordingly. From what I know about PHP and ways it works, I am afraid that this is not possible. Or am I wrong and there is still hope for my dreams? :) If I am right, what other choices do I have? I was thinking about having javascript timer that would send every few seconds ajax request asking if there is something new. On server side there would be probably some field in database that would signalize needed update. I have never done something like that and I am not sure how hundreds of players accessing database every few seconds would affect server load and bandwith. What if there were thousands of players, or even more? Do you guys have better solution?

Share this post


Link to post
Share on other sites
Advertisement
Even if you use the AJAX model, the client must request information from the server, it doesn't work the other way around.

I'm assuming the client will either pass a cookie or ID data in each AJAX call to identify the session to the server. A cookie is better (to make session hijacking more difficult). The ID is the key to pulling appropriate events from the queue.

If you want some kind of message passing / event handling behavior, your client can use a javascript timer to poll an event queue every X seconds as you said. Don't introduce a unique timer on the client for each event that you want to poll, use a server side event queue to store triggered events and event data for each session.

Share this post


Link to post
Share on other sites
Quote:
Original post by y2kiah
Even if you use the AJAX model, the client must request information from the server, it doesn't work the other way around.


OK, so I was right :) it is not possible that way

Quote:

I'm assuming the client will either pass a cookie or ID data in each AJAX call to identify the session to the server. A cookie is better (to make session hijacking more difficult). The ID is the key to pulling appropriate events from the queue.


I will worry about identifying client later, for now I just need to get info I need.

Quote:

If you want some kind of message passing / event handling behavior, your client can use a javascript timer to poll an event queue every X seconds as you said. Don't introduce a unique timer on the client for each event that you want to poll, use a server side event queue to store triggered events and event data for each session.


Yes, I planed to do it like this. One timer will be more than enough.

Thanks for your input

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement