470,866 Members | 1,922 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,866 developers. It's quick & easy.

PHP weirdness

Hey there,

I've written a script that calls AWStats to generate static statistics pages
for a given site on a certain month, and place those files into a directory
for that month... It has been working fine up until 31st of July, but when
the 1st of August came around, it mysteriously stopped doing anything...
here's is the code, can anyone here see anything screwy with it?

=== PHP Code begin ===
#!/usr/bin/php
<?
//
// AWStats history script.
//
// This script is designed to execute awstats_buildstaticpages.pl
// and output to a different directory each month
//

//
// Directory containing log files to be analysed
//
$logdir = '/path/to/logs';

//
// the config file to use: awstats.$configfile.conf
//
$configfile = 'someuser';

//
// !-END USER CONFIG-!
// Do not modify below, unless you know exactly what you're doing
//

$month = date('m');
$outputdir = $logdir . '/' . $month;

switch($month) {

case 01:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 02:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 03:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 04:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 05:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 06:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 07:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 08:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 09:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 10:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 11:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

case 12:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl
/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -mo
nth=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`
;

break;

default:

$result = "Could not generate stats! " . date('M j g:ia y') . "\n";

break;

}

$resultfile = $logdir . '/AWSResult.txt';

$fh = fopen($resultfile, 'w');
fwrite($fh, $result);
fclose($fh);
=== PHP Code end ===

So, I have sites that have 06, 07 etc directories where I want them, and the
AWSResult.txt file used to contain the output from
awstats_buildstaticpages.pl, but now I just get the default "Could not
generate stats!" error. The $configfile, $month and $outputdir vars are all
set exactly how I expect them to be, so I'm not sure why it isn't picking up
the fact that the $month var is '08' and skips to the 'default' instead of
'case 08' ... HELP !!! Like I said it was working without a hitch up until
the 1st of August.

Thanks in advance...

Regards,

Aidan
Jul 17 '05 #1
3 1901
Here's a better formatted version of the code...

=== PHP code begin ===
#!/usr/bin/php
<?
//
// AWStats history script.
//
// This script is designed to execute awstats_buildstaticpages.pl
// and output to a different directory each month
//

//
// Directory containing log files to be analysed
//
$logdir = '/path/to/logs';

//
// the config file to use: awstats.$configfile.conf
//
$configfile = 'someuser';

//
// !-END USER CONFIG-!
// Do not modify below, unless you know exactly what you're doing
//

$month = date('m');
$outputdir = $logdir . '/' . $month;

switch($month) {

case 01:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 02:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 03:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 04:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 05:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 06:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 07:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 08:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 09:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 10:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 11:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

case 12:

if(!(is_dir($outputdir))) {

mkdir($outputdir, 0755);

}

$result = `perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -config=$configfile -month=$month -update -dir=$outputdir -diricons=http://domain.com/awstatsicons`;

break;

default:

$result = "Could not generate stats! " . date('M j g:ia y') . "\n";

break;

}

$resultfile = $logdir . '/AWSResult.txt';

$fh = fopen($resultfile, 'w');
fwrite($fh, $result);
fclose($fh);
=== PHP code end ===

That should be a bit more readable...

Thanks again
Jul 17 '05 #2
Aidan <ai***@linknet.com.au.unspam> wrote:

[snipped code]

BTW terrible code duplication ! Why not replace it with:
if($month >0 && $month <13)

(and $month=(int)date(...);)
case 08:
case 09:


Take a look at the numbers section in the reference manual... numbers
with a leading 0 are octals.... so only 0 to 7 are legal... 08 and 09
are illegal sequences !

--

Daniel Tryba

Jul 17 '05 #3

"Daniel Tryba" <ne****************@canopus.nl> wrote in message
news:ce**********@news.tue.nl...
Aidan <ai***@linknet.com.au.unspam> wrote:

[snipped code]

BTW terrible code duplication ! Why not replace it with:
Yeah it was a super quick hack... thanks for the suggestion
if($month >0 && $month <13)

(and $month=(int)date(...);)
case 08:
case 09:


Take a look at the numbers section in the reference manual... numbers
with a leading 0 are octals.... so only 0 to 7 are legal... 08 and 09
are illegal sequences !

Ahhh, of course... you're a life saver my friend.. cheers
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Corne' Cornelius | last post: by
1 post views Thread by (Pete Cresswell) | last post: by
5 posts views Thread by Phil Weber | last post: by
5 posts views Thread by David Thielen | last post: by
1 post views Thread by rhino | last post: by
26 posts views Thread by Prisoner at War | last post: by
2 posts views Thread by JYA | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.