Situation: I have a perpetual PHP CLI script running whenever my computer is powered on. Every minute, it launches a bunch of sub-processes which each do some work in parallel. (I do it like this because if I just run the routines one by one in the main script, they often take much longer than one minute, and then my system becomes unreliable.)
Most of the time, this works perfectly as intended (after a lot of fine-tuning of all sorts). However, there is a situation which I have so far been unable to account for:
Sometimes, the network connection to my VPN (OpenVPN) unexpectedly goes down. It's been happening almost daily lately. Each time this occurs, my "sub-scripts" (which mainly do network-related work) get stuck trying to retry connecting many times (and waiting for timeout each time, etc.). The end result is that more and more copies of these scripts stack up, eventually making my machine crawl on its knees when I come back and realize that it has 30 copies of each of these sub-scripts running at the same time, all stuck in an almost-eternal loop because they cannot detect that the network is down.
(Yes, I have the cURL options for timeout/connecttimeout, etc.)
For this reason, I would like to be able to detect "offlineness". This proved to be much more difficult than I at first imagined. Is there some obvious way to do this on the command line on Windows? Of course, my system is developed to be fully cross-platform, so I'd like to know this for Linux and macOS as well, but since I'm primarily on Windows, that's the most important for me personally right now.
Basically, I would ideally want to be able to run "isthatlittlenetworkiconinthebottomrightcornerofthescreenlitgreen.exe" which returns 0 or 1.
(With built-in tools.)
Hopefully, somebody will have a sane, cross-platform idea for checking this. Perhaps even PHP itself has this built in as a function? (Yeah, right...)