【发布时间】:2018-11-15 08:34:02
【问题描述】:
我有以下脚本:
<?
$dir = './var/session';
$fi = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS);
$fileCount = iterator_count($fi);
// echo 'Directory Count: ';echo $fileCount;
//echo '<br />';
$bytes = 0;
foreach (new DirectoryIterator('./var/session') as $file) {
if ($file->isFile()) {
$bytes += $file->getSize();
}
}
//echo $bytes;
//echo ' Bytes';
//echo '<br />';
$MBbytes = number_format($bytes / 1048576, 2);
//echo $MBbytes;echo ' MB';
$from = "mail@example.com";
$to = "admin@example.com";
$subject = "Session MB = " .$MBbytes;
$message = "Session MB = " .$MBbytes."\n Directory Count: " .$fileCount;
$headers = "From:" . $from;
mail($to,$subject,$message, $headers,"-fmail@example.com");
// echo "Email sent";
我正在尝试通过 cron 运行此脚本。当我通过在浏览器中访问它来运行它时,它工作正常。我已经使用了所有可以使用的 cron 表达式,但没有发送电子邮件。有什么建议?
【问题讨论】:
-
您确认正在调用脚本吗?这是第一步,因此您可以知道这是 cron 问题还是编码问题(或代码运行后的问题)。
-
如何确认?
-
一种简单的方法是写入日志文件。如果该文件未创建或更新,则该脚本未执行。
-
你使用的是什么 cron 表达式?这可能会有所帮助。
-
目前正在尝试这个:* * * * * wget example.com/session-folder-size.php