我无法找到如何最佳实践解决以下情况的信息。
Cron运行定义间隔脚本(见下文)。如果一切正常,将会发生,一切正常。但是,如果发生错误(在代码注释// VALIDATION ...中)我不知道错误(我必须在浏览器中手动运行脚本并通过var_dump调试,回显,浏览所有日志等。 )。
我想丰富一个状态,我可以获得Cron作业的最终报告(例如http://www.vblog.ch/wp-content/uploads/2012/11/veeam-report.jpg) - 基本数据(作业的摘要结果)+发生错误或运行正确的信息(例如文件XXX已处理,无法删除文件,目录XXX不存在)。此外,如果程序的一部分继续进一步发生错误(请参阅脚本中的注释)。
谢谢你,Petr
#region <<< Process all files >>>
// get all eported directories with files
$xpath = new DOMXPath($myDOMDocumentConfiguration);
$searchNodes = $xpath->query('//Configuration/Directory');
// go throw all directories
foreach( $searchNodes as $searchNode )
{
// VALIDATION
// ERROR CAN BE HERE - DIRECTORY NOT EXISTS
// TRY NEXT DIRECTORY
// find all files in defined path (pathnames matching a pattern)
foreach(glob($searchNode->getAttribute('FilePathD')) as $strFile)
{
// convert csv file to array
$arrFiles = Record::ConvertCsv2Array($strFile);
// VALIDATION
// ERROR CAN BE HERE - CANNOCT CONVERT CSV FILE TO ARRAY
// TRY NEXT FILE
// go throw all items
foreach($arrFiles as $FileItem)
{
// prepare SQL query and insert ot to database
$strSqlQuery = 'INSERT INTO ....';
// VALIDATION
// ERROR CAN BE HERE - BAD INSERT TO DATABASE
// IGNORE, APPEND ONLY INFORMATION TO LOG
}
// if file is inserted to database, delete it
unlink($FileItem);
// VALIDATION
// ERROR CAN BE HERE - CAN NOT DELETE FILE
// IGNORE, APPEND ONLY INFORMATION TO LOG
}
// VALIDATION
// ERROR CAN BE HERE - DIRECTORY NOT EXISTS
// TRY NEXT DIRECTORY
// delete all analytics files in defined path (pathnames matching a pattern)
foreach(glob($searchNode->getAttribute('FilePathA')) as $strFile)
{
// cmr files are onyl analytics - delete it
unlink($strFile);
// VALIDATION
// ERROR CAN BE HERE - CAN NOT DELETE FILE
// IGNORE, APPEND ONLY INFORMATION TO LOG
}
}
#endregion
echo '=== Task has been completed ===';