我可以使用 ||和&&在一起?
can i use || and && together?
我正在尝试打开日志文件并查看文本是否不存在,如果不存在则继续,但同时我想检查其日志文件是否已按邮件发送。
public function start() {
$pattern = $this->config["twp_pattern"] ?? '*.log';
$pathLog = (isset($this->config["twp_path"])) ? trim($this->config["twp_path"], '/') : 'var/log';
$lastRun = (isset($this->config['twp_last_run'])) ? str_replace('T', ' ', $this->config['twp_last_run']) : false;
$path = getcwd() . '/' . $pathLog . '/' . $pattern;
$this->now = new \DateTime();
foreach (glob($path) as $log) {
$open = fopen($log, 'r') or die ('File opening failed');
$content = fread($open,filesize($log));
var_dump($content);
fclose($log);
if (!$lastRun || filectime($log) < strtotime($lastRun) && $this->checkIfAlreadyExists($content) === false) {
continue;
}
$logs[] = $log;
}
if (!empty($logs)) {
$success =$this->sendMail($logs);
}
if($success === false){
return false;
}
$this->setLastRun();
return true;
}
public function checkIfAlreadyExists($content){
if (!preg_match_all('/already exists/', $content)) {
echo "is not there";
return false;
}else{
echo "is there";
return true;
}
}
我的问题是即使电子邮件已发送,它会在我 运行 时再次发送
函数启动()
如果我删除 && $this->checkIfAlreadyExists($content) === false
,它将不再按已发送的邮件发送日志。谁能发现我的错误?谢谢
已通过更改我的 if 语句修复
if ((!$lastRun || filectime($log) < strtotime($lastRun)) || ($this->checkIfAlreadyExists($content))) {
continue;
}
感谢您的宝贵时间和帮助! <3
我正在尝试打开日志文件并查看文本是否不存在,如果不存在则继续,但同时我想检查其日志文件是否已按邮件发送。
public function start() {
$pattern = $this->config["twp_pattern"] ?? '*.log';
$pathLog = (isset($this->config["twp_path"])) ? trim($this->config["twp_path"], '/') : 'var/log';
$lastRun = (isset($this->config['twp_last_run'])) ? str_replace('T', ' ', $this->config['twp_last_run']) : false;
$path = getcwd() . '/' . $pathLog . '/' . $pattern;
$this->now = new \DateTime();
foreach (glob($path) as $log) {
$open = fopen($log, 'r') or die ('File opening failed');
$content = fread($open,filesize($log));
var_dump($content);
fclose($log);
if (!$lastRun || filectime($log) < strtotime($lastRun) && $this->checkIfAlreadyExists($content) === false) {
continue;
}
$logs[] = $log;
}
if (!empty($logs)) {
$success =$this->sendMail($logs);
}
if($success === false){
return false;
}
$this->setLastRun();
return true;
}
public function checkIfAlreadyExists($content){
if (!preg_match_all('/already exists/', $content)) {
echo "is not there";
return false;
}else{
echo "is there";
return true;
}
}
我的问题是即使电子邮件已发送,它会在我 运行 时再次发送
函数启动()
如果我删除 && $this->checkIfAlreadyExists($content) === false
,它将不再按已发送的邮件发送日志。谁能发现我的错误?谢谢
已通过更改我的 if 语句修复
if ((!$lastRun || filectime($log) < strtotime($lastRun)) || ($this->checkIfAlreadyExists($content))) {
continue;
}
感谢您的宝贵时间和帮助! <3