I've built a very basic game around an 50ms gameloop (setinterval) and I've been considering how to fetch player positions. So far I've had the idea to use ajax to post the player position to a php script which will update a sql database, then select all player positions and pass them back in the return. However i'm concerned that this may hit a race condition or that the entire action will simply take to long >5ms, it also feels wasteful to repeatedly poll the sql database for the same data (player positions). Is there a more effective way to achieve this? I've started looking at caching and sharing objects between php instances but not found much info
It probably is not needed to write this to your database all the time. Use an extension like APCu. You could still write the player's positions to the database at regular intervals with a background process.
It probably is also not needed to return all user positions, but only those that are nearby. From your comment I understood that your game has different worlds, so you would only need to return the user positions that relate to the world the player is in. And even then you could limit it further based on distance, if the player's view on that world only covers a part of it at any time.