PHP weirdness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aidan

    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_buildst aticpages.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.$config file.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($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 02:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 03:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 04:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 05:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 06:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 07:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 08:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 09:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 10:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 11:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 12:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

    $result = `perl
    /usr/local/awstats/tools/awstats_buildst aticpages.pl -config=$configf ile -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($resultfi le, '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_buildst aticpages.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


  • Aidan

    #2
    Re: PHP weirdness

    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_buildst aticpages.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.$config file.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($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 02:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 03:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 04:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 05:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 06:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 07:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 08:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 09:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 10:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 11:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

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

    break;

    case 12:

    if(!(is_dir($ou tputdir))) {

    mkdir($outputdi r, 0755);

    }

    $result = `perl /usr/local/awstats/tools/awstats_buildst aticpages.pl -config=$configf ile -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($resultfi le, 'w');
    fwrite($fh, $result);
    fclose($fh);
    === PHP code end ===

    That should be a bit more readable...

    Thanks again

    Comment

    • Daniel Tryba

      #3
      Re: PHP weirdness

      Aidan <aidan@linknet. com.au.unspam> wrote:

      [snipped code]

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

      (and $month=(int)dat e(...);)
      [color=blue]
      > case 08:
      > case 09:[/color]

      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

      Comment

      • Aidan

        #4
        Re: PHP weirdness


        "Daniel Tryba" <news_comp.lang .php@canopus.nl > wrote in message
        news:cen2nr$bgm $1@news.tue.nl. ..[color=blue]
        > Aidan <aidan@linknet. com.au.unspam> wrote:
        >
        > [snipped code]
        >
        > BTW terrible code duplication ! Why not replace it with:[/color]

        Yeah it was a super quick hack... thanks for the suggestion
        [color=blue]
        > if($month >0 && $month <13)
        >
        > (and $month=(int)dat e(...);)
        >[color=green]
        > > case 08:
        > > case 09:[/color]
        >
        > 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 ![/color]


        Ahhh, of course... you're a life saver my friend.. cheers


        Comment

        Working...