user3759159 user3759159 - 1 year ago 131
PHP Question

Wait for VPN connection to be established loop

I was looking for a way in PHP to check and wait for vpn connection (tun0 interface) to come up before continuing with the code
here is what I come up with but it's not seeing any change after interface tun0 is up

$val = exec("/bin/netstat -i | grep tun0 | wc -l");
while($val == "0")
echo "Still Not Connected\n";
echo "VPN Connected";

Answer Source

Your command is just not in the loop :p

    $val = exec("/bin/netstat -i | grep tun0 | wc -l");

    if( $val == "0" ){ echo "Still Not Connected\n"; sleep(2); }

} while($val == "0")

echo "VPN Connected";

I'm using do-while structure because you will do at least one time the loop.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download