PHP - 静态变量使用不正确


PHP - Incorrect use of static variable?

我正在尝试在PHP中制作一个简单的代码,以决定何时可以进行查询。

我的代码看起来像这样:

$status = shell_exec("/usr/local/bin/gpio -g read 17");
static $status_lpv = 0;
if ($status == 1 )
{   
    if($status_lpv == 0)
    {   
        $status_lpv = 1;
        echo " do the job ";
    }
}
if($status == 0 )
{
    if($status_lpv == 1 )
    {
        $status_lpv = 0;
        echo "do another job ";
    }
}

我的变量$status_lpv始终为 0。我做错了什么?

尝试将

代码包装到函数中(如果还没有)并调用函数

不能在(静态)变量中存储 http 调用之间的状态。

您需要持久存储,锁定等(例如,尝试数据库)