开发者

JSON file is corrupt or unavailable Render 1 is up and running Render 2 is up and running

开发者 https://www.devze.com 2023-03-24 01:35 出处:网络
I\'ve created a piece of code that reads information from a json formatted file, and should respond differently with each \"status code\". Everything works, but one statement always runs even when it

I've created a piece of code that reads information from a json formatted file, and should respond differently with each "status code". Everything works, but one statement always runs even when it doesn't seem to be true. The statement is marked with asterisks.

 <?php
    $file = file_get_contents("/system/status"); //Get status file
    $output = json_decode($file); //Decode it into variables
    $render1 = 0; //Declare variables
    $render2 = 0;

    if ($output->render1 & $output->render2) //If variable not available, do not replace
    {
      $render1 = $output->render1;
      $render2 = $output->render2;
    }

    if ($render1 || $render2 != 1 || 2 || 3) //If value is zero, item is corrupt
    {
        echo "Status file is corrupt or unavailable"; ***** This always runs, no matter 
        *******what the actual value
    }开发者_JS百科

    if ($render1 == 1)
    {
        echo "Render 1 is up and running";
    }

    if ($render2 == 1)
    {
        echo "Render 2 is up and running";
    }

    if ($render1 == 2)
    {
        echo "Render 1 is offline";
    }

    if ($render2 == 2)
    {
        echo "Render 2 is offline";
    }

    if ($render1 == 3)
    {
        echo "Render 1 is offline for scheduled maintinance";
    }

    if ($render2 == 3)
    {
        echo "Render 2 is offline for scheduled maintinance";
    }
   ?>

If the $render1 and $render2 variables are 1, my program would output Status file is corrupt or unavailable Render 1 is up and running Render 2 is up and running Any ideas?


if ($render1 || $render2 != 1 || 2 || 3)

Is not gonna work, basicly you are asking if $render1, OR $render2 not eequals 1, OR 2, OR 3 2 and 3 will always be true, and so the if is always triggered


this may help

if ($render1 || !in_array($render2, array(1, 2, 3)) )
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号