开发者

Logging System from txt file to database

Iam thinking changing the log file into database table.

I execute multiple shell_exec and it run in the background, example:

<?php
 shell_exec("php process.php > /dev/null 2>&1 &");
 shell_exec("php process.php > /dev/null 2>&1 &");
 shell_exec("php process.php > /dev/null 2>&1 &");
 shell_exec("php process.php > /dev/null 2>&1 &");
?>

While process.php is running/looping - it will generate a log, assume process ID is 123

log_123.txt File:

-----------------------------------------
Process ID: 123
- Loggin In
- Logged OK
- Checking xxxx (xxxxx)
- Sending Info
- Received xxxx 25252525
- Completed
------------------------------------------
Process ID: 123
- Loggin In
- Logged OK
- Checking xxxx (xxxxx)
- Sending Info
- Received xxxx 23424
- Completed
------------------------------------------
Process ID: 123
- Loggin In
- Logged OK
- Checking xxxx (xxxxx)
- FAIL
------------------------------------------

(Each process have a log file)

Now I wanted to change text files 开发者_如何学Clogging into database table log, what is the best way to do this?

I came up with this solution:

CREATE TABLE IF NOT EXISTS `log` (
  `log_id` int(11) NOT NULL AUTO_INCREMENT,
  `process_id` int(11) NOT NULL,
  `process_date` datetime NOT NULL,
  `log_output` varchar(200) NOT NULL,
  `log_time` datetime NOT NULL,
  PRIMARY KEY (`log_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


You have the table, you have the file. It sounds like you just need to modify the process.php file to update your database instead of the test file.

If you are using mysql http://php.net/manual/en/book.mysqli.php is a good place to start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜