Php PING slowing page return?

Asked

Viewed 169 times

0

I am setting up a monitoring system and some other functions, among them I am creating a Dashboard that gives me the return of the equipment "ON" or "OFF" by ping with the following code;

<?php
        $host="10.41.5.9";
        exec("ping -c 4 " . $host, $output, $result);
        if ($result == 0)
        {

        ?>
        <div class="w3-quarter">
          <div class="w3-container w3-green w3-padding-16" id="class_ping">
            <div class="w3-left"><i class="fa fa-lightbulb-o w3-xxxlarge"></i></div>
            <div class="w3-right">
             <h5>UNIDADE CEARÁ</h5>
            </div>
            <div class="w3-clear"></div>

            <h6>Impressora Atual</h6>
            <span><strong><?php echo $impressora1;?></strong></span><br>
            <i class='fa fa-gear fa-spin'></i> - Impressora ONLINE
            </div>
        </div>
        <?php
        }else{
        echo  "";
        ?>
        <div class="w3-quarter">
          <div class="w3-container w3-red w3-padding-16" id="class_ping">
            <div class="w3-left"><i class="fa fa-lightbulb-o w3-xxxlarge"></i></div>
            <div class="w3-right">
              <h5>UNIDADE CEARÁ</h5>
            </div>
            <div class="w3-clear"></div>

            <h6>Impressora Atual</h6>
            <span><strong><?php echo $impressora1;?></strong></span><br>
            <i class='fa fa-gear'></i> - Impressora OFFLINE
            </div>
        </div>
        <?php
        }
        ?>

The question itself, I wonder if there is how to leave the ip to drip after loading the page, for it to test the ping after the page has already given the load ! Thank you.

  • But if you need the result to display the page, how it would run after?

  • So this ping is the return of a printer, it’s running to display on the Dash of that page, what’s happening now is that the page is taking a long time to load because it’s running the ping test, what I’d like to know is if it’s possible is, load the page and after loading it ping.

  • Can bring back ping from an AJAX request; what do you think?

  • It’s a good one, but I’m not very familiar with AJAX, I entered the php world a little while ago heheh, I don’t know how to apply it yet , but I’ll give a study to see how I can apply it in my code. Is there an example to see how it’s done ?

  • PHP works by execution, so there’s no way you can do what you want. If you want to load the page before ping, I suggest AJAX as @Andersoncarloswoss suggested

  • Show cHida, after this post I made me study more sinking ajax/Jquery by the need I have been having in my developments in the company. Thanks for the help !!!

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.