0

I am adding post view +1 whenever someone is loading the page in wordpress. so everytime someone reloads it automatically gets +1. this will cause to store very large value in meta value. is it ok?

1
  • If you are adding a new post_meta record every time, then yes it will and you shouldn't do that. If you are getting the current post count and just adding +1 and then updating the same record for that post, then it's fine. One additional post_meta record for each post on your site isn't going to be a huge issue. Commented Mar 12 at 16:36

1 Answer 1

0

Assuming this is just a plain whole number, the answer is yes, post meta values can be big, but it's the number of characters that determines how big it is, not the value they represent.

As for how big your post view count can get, that would be PHP_INT_MAX, so it depends on wether your server and PHP are 32bit or 64bit.

The largest integer supported in this build of PHP. Usually int(2147483647) in 32 bit systems and int(9223372036854775807) in 64 bit systems.

https://www.php.net/manual/en/reserved.constants.php#constant.php-int-max

So it will never be more than 19/20 characters long on a 64bit system, or 11 characters on a 32bit system.

At any point you can test this by setting the post meta value to PHP_INT_MAX and see if there are any issues.


But it doesn't matter, because storing view counts in post meta is extremely unreliable, and prone to race conditions. It's also fundamentally incompatible with CDNs and fullpage caches which will only count the first page view.

It's also terrible for performance and high traffic sites, because every page does a database write.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.