<?php function load_setting() { return (int) trim( file_get_contents( 'setting.pedro' ) ); } function load_counter() { return (int) trim( file_get_contents( 'counter.pedro' ) ); } function load_adcode($which) { return trim( file_get_contents( "ad{$which}.pedro" ) ); } function save_counter($count) { file_put_contents('counter.pedro',$count); } $counter = 1 + load_counter(); if($counter >= load_setting()) $counter = 0; save_counter($counter); echo load_adcode($counter); ?> Code (markup): Is it smart to save data to files like this? And any other suggestions?
Why do you need to load the counters ? Would be better for performance If you dont load the counters every time. You could make a cron job every hour to count the stats, not every time someone load the page. You have one log file that saves what ad is published and you make a summary every hour.