Re: Optimizing a string manipulation script.
- From: Alan Little <alan@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 07 Jun 2006 20:00:11 -0500
Carved in mystic runes upon the very living rock, the last words of
<Cleverbum@xxxxxxxxxxx> of comp.lang.php make plain:
Alan Little wrote:
Carved in mystic runes upon the very living rock, the last words of
<Cleverbum@xxxxxxxxxxx> of comp.lang.php make plain:
I'm not really accustomed to string manipulation and so I was
wondering if any of you could be any help i speeding up this script
intended to change the format of some saved log information into a
CSV file while removing duplicate records.
The main problem is that the script currently takes about 20
seconds to execute, and were it to take much longer it would time
out.
Below is the script itself, and then some example lines from the
log file it processes:
<?
[snip]
?>
Whew!
How about an example of the output you're trying to achieve? That
might be easier.
Here we go then:
Try this:
<?php
$patt =
'!([^:]+:) \[([^:]+:\d\d:\d\d:\d\d) [+-](\d{4})\] '.
'(\d+\.\d+\.\d+\.\d+) (-) (-) "(\w+) (/[^ ]*) '.
'(HTTP/\d\.\d)" (\d+) (\d+) "([^"]+)" "([^"]+)"'.
"\n?".'!';
$log = fopen('log.csv', 'a');
$logfile = file_get_contents('logs.txt');
$logfile = ereg_replace("\r\n?", "\n", $logfile);
preg_match_all($patt, $x, $matches, PREG_SET_ORDER);
foreach($matches as $match) {
unset($match[0]);
$logline = implode(',', $match);
fputs($log, $logline."\n");
}
fclose($log);
?>
I don't know what those two blank log elements are after the IP, so this
pattern will only work when they're blank.
--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
.
- Follow-Ups:
- Re: Optimizing a string manipulation script.
- From: Cleverbum
- Re: Optimizing a string manipulation script.
- References:
- Re: Optimizing a string manipulation script.
- From: Alan Little
- Re: Optimizing a string manipulation script.
- From: Cleverbum
- Re: Optimizing a string manipulation script.
- Prev by Date: Re: Code not working
- Next by Date: How do you retrive drives and net work connections?
- Previous by thread: Re: Optimizing a string manipulation script.
- Next by thread: Re: Optimizing a string manipulation script.
- Index(es):
Relevant Pages
|