Which is least intensive - working out the unique hour in PHP or MySQL? -


i trying work out way track impressions in mysql without killing cheap-as-chips server doing quite bit @ peak times.

my idea record impressions per hour. need know least intensive way unique hour value be.

follow advice found here: https://rollbar.com/blog/post/2013/03/29/using-unique-indexes-for-fun-and-profit want create table track impressions per hour.

the tutorial suggest like:

insert hour_impression (hour, impressions) values (379015, 1) on duplicate key update impressions = impressions + 1 

now hour needs unique value best way generate unique value?

would having php work out hours since unix epoch efficient way or can mysql me?

if this:

insert hour_impression (hour, impressions) values (date_format(from_unixtime(now()), '%y%j%h'), 1) on duplicate key update impressions = impressions + 1 

i pretty confident work cost me in terms of amount of effort db being asked make vs working out in php , supplying data.

would quicker or less intensive?

$sql = "insert hour_impression (hour, impressions) values (" . date('yzg') . ", 1) on duplicate key update impressions = impressions + 1"; 

is there way have not considered?

am blowing mind trying figure out , makes little difference should not worry?

if goal efficient on ram used keys, using unsigned integer date best. having timestamp including hours , seconds won't idea if traffic grows.

strtotime(date('y-m-d h:00:00')) 

you have in 24 unique time values every day each hour. if go 'y-m-d h:i:s' format might 80k unique values each day.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -