Skip to content

Why is running Phaser on the server "something you really shouldn't do"? #6037

Closed

Description

@LZoog

Sorry in advance if this should be on StackOverflow or Phaser Forums. I'm filing this here since it might be a feature request, or just a request to update the documentation here with more details.

I'm using NextJS which allows my application to be rendered server-side. After searching for React + Phaser integration opens, I found this issue in ion-phaser, and was able to get the page with my Phaser app working by disabling SSR for that page (see this comment).

In that issue, I mention that I'm interested in getting it server-rendered, to which two others responded similarly, and I've also found similar questions online, making me believe this isn't an uncommon ask. I found this blog post on phasertutorials.com on a similarly asked question on Phaser Discourse and one or two other tutorials which I was planning on exploring, but this recommends setting up Phaser on the server in 'Headless' mode and as pointed out in a comment on that ion-phaser issue, the documentation specifically states, "This mode is meant for unit testing, not for running Phaser on the server, which is something you really shouldn't do."

It seems like it would be best practice to keep the state of the game on the client synced with a state on the server to validate client actions and prevent cheating. If not, how do you verify client actions are legit?

Someone else asked this question 3 1/2 years ago and didn't seem to get a satisfactory response ("you can add random code to ping your server with checksums" seems a bit messy), and a comment on a different post mentions, "Scaling would be a PITA.", but it's 6 years old and I'm not sure how accurate that is.

If it's not best practice to set it up in headless mode to run on a server, what's recommended?

Activity

  1. Arcanorum commented on Mar 13, 2022

    @Arcanorum

    Existing discussion from many years ago, but one that I always think back to when ever this question comes up, and think it holds up even today as a valid answer:

    Running Phaser on Node.js - How I did it and why you shouldn't do it

  2. LZoog commented on Mar 15, 2022

    @LZoog
    Author

    @Arcanorum thank you for the link 👍 I hadn't come across that one in my search and there's some helpful links in there.

    Some are saying that it's bandwidth and too resource-intensive. I wonder if anyone has benchmarks? There's some interesting comments (especially on page two) that talk about running it successfully:

    I personally tried running Phaser.js inside Node.js and sending the game state once every 100ms or so and the game was running smooth and Node.js was only using like 10% CPU. The bandwidth is not affected by the things you do on the server as long as you send only the parts of the game state that matter (player positions, velocities, healthbars, etc...).

    and this one:

    I don't think putting too much of a load on node.js by running Phaser on the server-side is a valid concern. The resource-intensive stuff in Phaser is all tied to rendering. Performance-wise, it's not going to make any difference by including Phaser's classes on the server-side... just as long as you strip out all the rendering logic.

    It seems like there's a few other architectural options to explore from that link you provided that I'd like to look into a little more closely. I guess there's not any Phaser docs on best practices for this (please correct me if I'm wrong), which is what I think would be ideal. I'm also a little confused as to why the blog post I linked with this tutorial is on phasertutorials.com if it's bad practice, but I suppose I don't know if they're directly affiliated with Phaser or not.

  3. locked and limited conversation to collaborators on May 6, 2022
  4. converted this issue into a discussion #6100 on May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions