恕我直言,最好的方法不是将您的跟踪器/记录器放在操作系统的较低级别,而是放在 PHP 本身中。
我的建议是编写一个 PHP 循环,尝试次数有限,尝试之间的等待时间更短,这样您就可以记录每个循环,以及每个循环的网络连接轮询结果。获得连接网络后,立即中断循环。如果循环结束且未获得网络访问权限,则发出相关消息/业务操作。
define("MAX_ATTEMPT_COUNT", 10);
define("WAITING_TIME", 60);
$NetworkAccess = false;
$fd = fopen("netpoll.log", 'a');
if (!$fd) die("I thought I could open netpoll.log but I can't.");
for($i=1; $i<=MAX_ATTEMPT_COUNT; $i++) {
fwrite($fd, "Entering loop #" . $i);
$NetworkAccess |= pollNetwork(); // can be |= or simply =
if ($NetworkAccess) {
fwrite($fd, "network access acquired, exiting loop.");
break;
}
fwrite($fd, "No cigar, I'll try again in " . WAITING_TIME . " seconds.");
sleep(WAITING_TIME);
}
if(!$NetworkAccess) {
fwrite($fd, "No network access after " . MAX_ATTEMPT_COUNT*WAITING_TIME . " seconds, giving up.");
}
fclose($fd);