• Querying a Source Server using PHP
    7 replies, posted
Hello everyone, I know this question has been asked before but after about a week's worth of searching I can't seem to find out how to get this working properly. My goal is to simply query my Garry's Mod servers and print simple information such as the current map and player count to my web page. There are already several articles, forums and libraries around on the internet to do this. For example, [URL="https://github.com/xPaw/PHP-Source-Query"]this source query[/URL] or [URL="http://oxidemod.org/threads/php-simple-server-query.2374/"]this PHP script[/URL]. However, I have been having problems and after a lot of troubleshooting I cannot get these working. On the github page for the [URL="https://github.com/xPaw/PHP-Source-Query"]xPaw Source Query[/URL], it shows the following: [IMG]http://i.imgur.com/mPoabi9.png[/IMG] I'm wondering if this could have anything to do with my issues? When trying the xPaw [URL="https://github.com/xPaw/PHP-Source-Query/blob/master/Examples/View.php"]Examples included[/URL] in the .zip file, changing the IP and testing the page on two separate web servers, both have printed PHP error messages where the connections could not be made. I have tested with different server IP addresses that are all of online Garry's Mod servers! I have tried other source scripts that I have found online and none seem to be producing any results on my web server. If it at all matters my web server is on shared hosting and has php7 with gmp. Any help to get this working would be much appreciated. I am experienced in HTML and CSS but not enough in PHP to write my own script, or thus far be able to figure out why none of this is working. If at all possible, I am trying to have the query work from pure PHP or use a precompiled PHP library, such as the xPaw Query library. Thank you in advance!
In Socket::Open you could var_dump/print/echo $ErrNo and see what (if any) error code was returned.
Most likely, both of your "separate web servers" block outgoing UDP connections either alltogether, or on the port you're trying to connect to. This is common practice on shared hosting, to prevent people using their webhosting for DoS attacks.
[QUOTE=tschumann;52326698]In Socket::Open you could var_dump/print/echo $ErrNo and see what (if any) error code was returned.[/QUOTE] I tried this and it prints out "0" at the top of the page. On the page I am getting a "Failed to read any data from socket" error, if that helps: [IMG]http://i.imgur.com/YGrni0C.png[/IMG] [QUOTE=TrinityX;52326786]Most likely, both of your "separate web servers" block outgoing UDP connections either alltogether, or on the port you're trying to connect to. This is common practice on shared hosting, to prevent people using their webhosting for DoS attacks.[/QUOTE] That would make sense on the shared hosting. However, the second server I tested on is a linux-based web server on my own network, with all ports temporarily open on my router through to the server for testing.
By the looks of your stack trace it did connect but the server returned no data? Maybe try dumping the contents of the Socket's $Buffer attribute and see what if there are any clues in there.
[QUOTE=tschumann;52332369]By the looks of your stack trace it did connect but the server returned no data? Maybe try dumping the contents of the Socket's $Buffer attribute and see what if there are any clues in there.[/QUOTE] This is really odd. I copied the Example.php file which calls the query and added a var_dump() for the $Buffer. It prints out an array with all of the information onto the page absolutely fine, and I have since turned off the port forwarding rules I had for it. I am wondering if it is in fact an issue on the server side, as I can ping certain servers but not others. Maybe it is something to do with servers not accepting the incoming UDP connection? I've also copied the same script that returned that array and put it onto my shared hosting server. It's throwing up the same failed to read any data from socket error. I'm guessing that is because of a blocked UDP connection?
No idea - I haven't used raw sockets in years. Do you know if your server has any sort of connection blocking?
You could also fire up wireshark and look at what actually is sent over the network [editline]13th June 2017[/editline] Or trying another tool to connect and see if it is a problem with that tool.
Sorry, you need to Log In to post a reply to this thread.