mattvh / MCServerStatus

Query Minecraft servers for the online players, message of the day, and whether they're online or not.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when server offline

johnsondelbert1 opened this issue · comments

i get this error when a server is offline Warning: stream_socket_client(): unable to connect to tcp://play.stormforgemc.com:25565 (Connection timed out) in /homepages/5/d382005148/htdocs/minecraft/plugins/serverlist/MCServerStatus/Minecraft/Stats.php on line 10

The original Joel Larson version at https://github.com/JoelLarson/MCServerStatus is far better imo, actually validates the response, returns error information and distinguishes between offline and error states. Plus most importantly, doesn't throw PHP warnings (in any version, its just as 5.3 compliant, just doesn't use namespaces or a silly data object which breaks SRP...)

Author: If you want to break things up, at least use dependency injection. Have the Server object accept a Retriever object in the constructor or after startup - from which the Server populates itself. Ideally this server should implement/expect an Interface, but leaving it as a generic (well named) parameter is quite fine. Type safety in PHP is an illusion.

Then at least you can again easily use multiple different receiver implementations, such as ones with different timeouts.

Not to mention the current code doesn't even use the bundled Server data object class, it just instantiates StdClass... Horrible.

Also if you're going to use a static factory method to populate an object, have it create the object, and put it in the same class as the model implementation itself. What you've done is effectively use a separate class as a namespace, within a namespace, which is a different namespace to the data object itself, but within the same namespace... At that point you'd be better off just using a global function, since it's namespaced anyway.

I actually thought Joel Larson's version was too "broken up" at the time I pulled it and I was working on trying to find equilibrium between my original simple class and the Joel's PSR-0 compatible fork. I might play around with it again and think about reverting. The library is a mess in its current state.

I'm not familiar with dependency injection. That's where you pass an object a class depends on through the constructor or a setter instead of instantiating it within the dependent class?