加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

流量止损代码

(2012-07-08 18:57:02)
标签:

杂谈

    痛定思痛,小本买卖,流量费用是关键,所以什么上验证码都不靠谱,因为哪怕一个请求回吐1K字节,量大了也吃不消,最简单的方法是,流量花超了,就停服,这样就安全了,适合小本经营业主。
    夜里也能睡好觉,最后一道防线,避免重大损失。

#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/stat.h"
#include "stdint.h"
#include "time.h"

const uint32_t max_log_size = 15093232;

int main(void)
{
        time_t now;
        struct tm *tv = NULL;
        struct stat sb;
        char log_file_name[256];

        for(bool stop =false;!stop;sleep(60))
        {
                time(&now);
                tv = localtime(&now);

                sprintf(log_file_name,"access_log_%ddd",tv->tm_year+1900,tv->tm_mon+1,tv->tm_mday);
                if (stat(log_file_name, &sb) == -1)
                {
                        fprintf(stderr,"access_log not found!!!");
                }

                if( (uint32_t) sb.st_size > max_log_size )
                {
                        stop = true;
                }

                fprintf(stderr,"log_name:%s\tfile_size:%d\n",log_file_name,(uint32_t) sb.st_size);
        }

        fprintf(stderr,"services stop");
        system("sh stop_service.sh");

        return 0;
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有