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 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目