1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Check if server is online from the web

Discussion in 'Facepalm' started by Samantha, Jun 17, 2017.

  1. Samantha

    Samantha Spider

    Messages:
    9
    GitHub:
    mcwardsam
    I don't even know if this is allowed here, but I need to know how you ping a PocketMine server from a web server using PHP? Not querying it, just want to gets its status, like "online" or "offline". Please don't send me your querying classes, I only need to know a fast and simple method. Thanks again :)

    If it's not okay to post here, please delete this Thread
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you would still need the query tools to query the server, if it returns smth then it's not offline
    OR UNTESTED fopen(serverip:\port) and see if there's any respond
     
  3. Samantha

    Samantha Spider

    Messages:
    9
    GitHub:
    mcwardsam
    I don't think that works, how do you it without putting a timeout on it?
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you might just have to query it for respond, but what cause you to try to evade using query libraries?
     
  5. Samantha

    Samantha Spider

    Messages:
    9
    GitHub:
    mcwardsam
    Because I'm a scrub and it's kinda hard to use and understand them
     
    jasonwynn10 likes this.
  6. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    You could use MCPE banners which uses the MCPE protocol to query the server, so it will work regardless of whether query is enabled

    PHP:
    if(array_key_exists ("connected"json_decode(file_get_contents("https://b.mcpe.me/" $serverAdress "/json"), true))){
     
    // server is online
    }
    else{
    // server is offline
    }
    Or you could use mcapi which is bigger and has more server power, but will only work if query is enabled

    PHP:
    if(json_decode(file_get_contents("https://mcapi.ca/query/" $serverAdress "/mcpe"), true)["status"] === true){
     
    // server is online
    }
    else{
    // server is offline
    }
     
    jasonwynn10, BEcraft and SOFe like this.
  7. Samantha

    Samantha Spider

    Messages:
    9
    GitHub:
    mcwardsam
    Wait, what about the port? Xd
     
  8. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    Oh, $serverAddress can be a string like "example.com:19132" for both services. If you don't specify the port, it uses 19132.
     
    jasonwynn10 and Samantha like this.
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Querying the server might be inefficient since the server may be laggy. I recommend having a CGI somewhere else and connecting to the CGI directly to retrieve a cached status (cached for several seconds) for better performance.
    Hormones does something like this -- it regularly updates the timestamp in a row in the hormones_tissues table that represents the current server, so if the timestamp is checked from another client to be less than 5 seconds before current timestamp, the server is considered online.
     
    jasonwynn10, Thunder33345 and falk like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.