Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:36:28+00:00 2026-06-02T18:36:28+00:00

Is there a way I can convert this function to be ran from a

  • 0

Is there a way I can convert this function to be ran from a cron job and then insert the data it returns into a database?

public function ping($host, $port=25565, $timeout=0.1) {
//Set up our socket
    $beginning_time = microtime(true);
    $fp = fsockopen($host, $port, $errno, $errstr, $timeout);
    if (!$fp) return false;
    $end_time = microtime(true);

//Send 0xFE: Server list ping
    fwrite($fp, "\xFE");

//Read as much data as we can (max packet size: 241 bytes)
    $d = fread($fp, 256);

//Check we've got a 0xFF Disconnect
    if ($d[0] != "\xFF") return false;

//Remove the packet ident (0xFF) and the short containing the length of the string
    $d = substr($d, 3);

//Decode UCS-2 string
    $d = mb_convert_encoding($d, 'auto', 'UCS-2');

//Split into array
    $d = explode("\xA7", $d);

//Return an associative array of values
    return array(
        'motd'        =>        $d[0],
        'players'     => intval($d[1]),
        'max_players' => intval($d[2]),
        'latency'     => ($end_time - $beginning_time) * 1000);
}

The data it’s returning is what is in the array at the end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:36:30+00:00Added an answer on June 2, 2026 at 6:36 pm

    You can run any PHP file from the commandline. So the same command can be used in a cron. No need to convert anything.

    /usr/local/bin/php /home/test.php
    

    The path /usr/local/bin/php should be the location of your php binary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to convert HTML into XAML? I noticed that you can
Is there a way I can convert an mp3 file into a wav/aiff in
How can I convert this script into a MATLAB function? clear all; set={AB02XY_1,ZT99ER_1,UI87GP_1}; fileData1
Is there any way we can convert text to speech in an iPhone app?
Is there a way I can Convert my Lockbox 2 Cipher text to LockBox
Is there any way how can i convert a nstimeinterval type value to a
Is there way that I can read the file from remote server using fopen
Is there a way I can control columns from code. I had a drop
Is there any way to execute a scalar-valued function from within a Derived Column
Is there any way by which we can directly convert a hexadecimal value to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.