duanhui5344 2017-02-28 10:37
浏览 42
已采纳

触发awstats从PHP更新

I am trying to trigger an update of AWStats from inside a PHP script.

I currently use a cron job to trigger the update, and simply copied the command line into an exec function within the script.

if(exec("/path/to/awstats.pl -config=domain.com -update")) {
    echo 'Logs processed';
}

However, this returns a false positive. Although the "Logs processed" line is displayed, AWStats has not processed the stats information.

AWStats does work perfectly when visited directly, and when running the update via the cron job, it just isn't from this PHP script. I have checked the error logs, there is not a problem with my script or with AWStats timing out.

Am I missing something?

For the record, this script is designed to purge the old data, update a blacklist of referrers to block spam, and then recompile the stats data from the log files. Yes, I am aware of the performance issues of using the SkipReferrerBlackList directive.

  • 写回答

1条回答 默认 最新

  • doufubian3479 2017-02-28 10:56
    关注

    It seems from your code that you think exec returns a boolean indicating success or failure. It doesn't, it just returns a string (the last line of output from the command). And strings (except "0" and an empty string) always evaluate to true.

    To debug the problem you should print the output of the command:

    exec("/path/to/awstats.pl -config=domain.com -update", $output);
    echo join(PHP_EOL, $output);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图