Jump to content

Recommended Posts

Basically, I've created a game serverlist in php.

 

After some time, I've noticed in the console of two of my game servers I noticed it's spamming connections every time a user connects to the page(this happens a LOT, since people check the SLN often), it's been causing a bit of lag ingame when there is 10+ simultaneous connections from my webserver.

 

Is there a way I can have the php code only execute every X minutes, so even if a user is connecting to the page, it will show the outputted data from the last check in?  I'm using the fsockopen function to check the server's status, and other methods to query the server for information.  

 

This is the last thing I need to do for this project to be perfect, some help would be greatly appreciated ^^

Link to comment
https://forums.phpfreaks.com/topic/292575-creating-a-game-serverlist/
Share on other sites

  • Solution

Yes there are many ways to do what you want.  One of the simplest and at the same time, highly performant is to use a caching product.  Seems like I've written volumes on this in the past, but the ones to look at are: APC (only if you're using php

 

I'd probably recommend you start with Redis because it just has so many features that can come in handy, and it can use memory frugally.  With the small amount of data you need to cache, it should be a very good fit for you.

 

So-- in summary your code will become:

 

 

1. Request serverlist data from redis.

2.  If found - display.  (Coming right out of memory, this will be lightning fast)

3. If not found - get list of game servers.  Store this data to cache with a time-to-live setting you find acceptable.  You can experiment with this setting to see what the sweet spot is for you in terms of freshness of data vs. buffering the users.  Start with 60 seconds probably.

 

 

The only fly in the ointment (other than installation and configuration of redis on your server(s) is that you need a php client.  Fortunately there are 2 options: a pure php version (predis) and a php extension written in C (phpredis).  In your case, go with phpredis if you can, but that can become an issue if you don't have the environment or sysadmin experience to navigate pecl or any issues pecl might have compiling phpredis.

 

I feel obligated to say that you can just dump this stuff in a "file" on the filesystem and use filesystem calls to look at the age of the file, and build your own cache that way as well, but that's old school and once you have redis available you may find that some of its other features enable you to quickly get new information up and running for your users.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.