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 7011147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:05:24+00:00 2026-05-27T22:05:24+00:00

I am working on an app which will allow me to login to a

  • 0

I am working on an app which will allow me to login to a remote telnet server and monitor statistics. The problem is that the telnet server has a minimum refresh rate of 10 seconds, and the refresh rate varies slightly depending on server load (the report itself has this refresh rate, not the server). I need the front-end of this system to refresh more often than every 10 seconds (5 seconds minimum). I have somewhat been able to accomplish this by forking, but eventually the timings synchronize (it’s a gradual process which I am assuming is due to remote server loads).

Child Code:(i have removed quite a bit of code relating to how the app logs in and accesses the report, but it is basically key-presses through 7 menus to get to the page which refreshes – I can include if needed):

// 1 - Telnet Handshaking and initial screen load
$sHandshaking = '<IAC><WILL><OPT_BINARY><IAC><DO><OPT_BINARY><IAC><WILL><OPT_TSPEED><IAC><SB><OPT_TSPEED><IS>38400,38400<IAC><SE>';
// 2-4 - Keypresses to get to report (login, menus, etc. - Removed)

// Loop and cache
while(1){
    //  4 - View Report
    $oVT100->listen(); 
    $reference = $temp;
    $screen = $oVT100->getScreenFull();
    if(empty($screen)){
        Failed:
        echo "FAILED";
        file_put_contents($outFile,array('html'=>"<div class=\"header\"><font color='red'>Why are things always breaking?!<font color='red'></div>"));
        goto restartIt; // If screen does not contain valid report, assume logout and start at top
    }else{
        $screen = parseReport($oVT100->getScreenFull());
        $temp = json_decode($screen);
        // Check old report file, if different save, else sleep a bit
        $currentFile = file_get_contents($outFile);
        if($screen !== $currentFile){
            file_put_contents($outFile,$screen);
            sleep(5);
        }else{
            sleep(1);
            //usleep(500000);
        }
    }
}

As you can see with the child’s code above, it logs in then infinite loops the report. It then writes the screen out to a cache file (if it is different from the existing file). As a dirty workaround to the refresh issue, I wrote a parent to fork:

$pids = array();

for($i = 0; $i < 2; $i++) {
    sleep(5);
  $pids[$i] = pcntl_fork();

  if(!$pids[$i]) {
    require_once(dirname(__FILE__).'/checkQueue.php');
    exit();
  }

}

for($i = 0; $i < 2; $i++) {
  pcntl_waitpid($pids[$i], $status, WUNTRACED);
}

I immediately noticed the timing offset and had to spawn three children instead of two to keep under 5 seconds; but the timing worked for a few days. Eventually, all the children were updating the file at the same time and I had to restart the parent. What would be the best solution to monitor the child processes so that I maintain a refresh interval of less than five seconds?

[EDIT]
This is not a running log, it is a file which contains current call statistics for a call center. The data in the cache file needs to be no less than 5 seconds old at any time, but eventually all of the children sync and write to the log at nearly the same time. The issue isn’t really with the local file, it is inconsistent remote server response times which eventually leads to the child processes running getting their report at the same time.

  • 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-05-27T22:05:25+00:00Added an answer on May 27, 2026 at 10:05 pm

    I’m hoping there’s a better solution, but here’s how I solved it – I feel kind of stupid for not having thought of this in the beginning:

    $currentFile = file_get_contents($outFile);
    if($screen !== $currentFile){
        if(time()-filemtime($outFile) > 2){
            file_put_contents($outFile,$screen);
            sleep(5);
        }else{
            echo "Failed, sleeping\r";
            sleep(2);
        }
    }else{
        sleep(1);
        //usleep(500000);
    }
    

    basically, I check the file write time of the cache file and if it is less than 2 seconds ago, sleep and re-execute loop. I was somewhat hoping there would be a solution contained within the parent app but I guess this works…

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

Sidebar

Related Questions

I am working on an app which requires that the user be logged in
I have made an android app which working fine. I implemented the Login functionality
Built a custom app that will allow users to add jobs to a system.
I used to have a small chat app(which was almost working), that uses PHP,
I am working on an app which will provide route for the student shuttle.
I'm working on a new feature in an existing Perl codebase that will allow
i am working on app which deals with proximity alerts. I can add proximity
I am working on an app which calls a rest web service. Sometimes the
I am working on an app which uses Commonslang.jar libraries. I was trying to
I am working on a app which requires me to store some directions for

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.