我有不同的服务器
$strarrServerIp = array('192.168.123.1','192.168.123.2');
$strarrLogsData = array();
foreach($strarrServerIp as $strServerIp ){
$strCommand = 'ssh abose@' . $strServerIp . ' cat /srv/www/vhosts/trunk/Logs/Log20130825.psi.log';
$strarrLogsData[] = shell_exec( $strCommand );
}
foreach( $strarrLogsData as $strJsonLogData ){
foreach( preg_split("/((\r?\n)|(\r\n?))/", $strJsonLogData ) as $strJsonLineLog ) {
display($strJsonLineLog);
}
}
服务器包含包含这种形式的 JSON 日志的文件。
{"timestamp":"2013-08-25 20:35:06 MDT","severity":"INFO","data":"1"}
{"timestamp":"2013-08-25 20:36:06 MDT","severity":"INFO","data":"15"}
{"timestamp":"2013-08-25 20:37:06 MDT","severity":"INFO","data":"32"}
{"timestamp":"2013-08-25 20:38:06 MDT","severity":"INFO","data":"25"}
{"timestamp":"2013-08-25 20:39:06 MDT","severity":"INFO","data":"5"}
我想将它们分成一个数组
array (
[0] => {"timestamp":"2013-08-25 20:35:06 MDT","severity":"INFO","data":"1"}
[1] => {"timestamp":"2013-08-25 20:36:06 MDT","severity":"INFO","data":"15"}
[2] => {"timestamp":"2013-08-25 20:37:06 MDT","severity":"INFO","data":"32"}
[3] => {"timestamp":"2013-08-25 20:38:06 MDT","severity":"INFO","data":"25"}
[4] => {"timestamp":"2013-08-25 20:39:06 MDT","severity":"INFO","data":"5"}
)
有什么建议么?我想要更好的东西
preg_split("/((\r?\n)|(\r\n?))/", $strJsonLogData )