From: Wada Hiroshi Date: 1998-06-05T19:51:39+09:00 Subject: [ruby-list:8205] Re: Web Counter 和田です。 In message "[ruby-list:8202] Re: Web Counter" on 98/06/05, akira yamada / やまだあきら writes: > scount = sprintf("%0{leng}d", sleng) if leng なるほど。今回の場合は、 scount = sprintf("%0#{leng}d",count.to_s) if leng にしました。 > カウンタ値を保持しているファイルをロックして > カウンタ値を読み取って > インクリメントして > 新しいカウンタ値を書き戻して > ロックを解放して > イメージの生成と > イメージの送出 > >のように順番を変えた方がよいのではないかと思うです. 半分寝ながら作っていたので、気が付きませんでした。 早速修正しました。 -- ネットワーク応用通信研究所 和田 寛 < hiroshiw@netlab.co.jp > #! /usr/local/bin/ruby # 表示桁数 leng = 6 # カウントを保存するファイル countfile = "/home/hiroshiw/.num" file = open(countfile) count = file.gets().to_i file.close newcount = count + 1 file = open(countfile,"w") file.flock(File::LOCK_EX) printf file,newcount.to_s file.close require "GD" # require "cgi-lib" print "Content-type: image/gif\n\n" scount = sprintf("%0#{leng}d",count.to_s) if leng font = GD::Font.new("Giant") im = GD::Image.new(font.width * scount.to_s.size ,font.height) white = im.colorAllocate(255,255,255) black = im.colorAllocate(0,0,0) bule = im.colorAllocate(0,0,255) im.string(font, 0, 0, scount, bule) im.interlace im.gif STDOUT