The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Count words in PHP or mysql?
I'm writing a plugin that needs to count the number of words in the first post of a thread. What would be better in this case? Selecting the pagetext and then counting in php or just doing everything with one mysql select statement?
OR should I just build something to count the number of words in each thread, store the value in the post table, and just select that when needed? |
#2
|
|||
|
|||
It depends; how much load do both versions cause and how long do both versions need to finish its execution?
|
#3
|
||||
|
||||
On what occasion, i.e. when and where do you intend to run this count?
|
#4
|
||||
|
||||
Quote:
Code:
SELECT LENGTH(pagetext) - LENGTH(REPLACE(pagetext, ' ', ''))+1 AS words FROM post WHERE parentid='0' AND threadid=123; Maybe I'm answering my own question here and should just store the value. I'm sure a select statement without math is less expensive, especially if you have a really long thread. |
#5
|
|||
|
|||
I'm pretty sure it would be faster to do this PHP. However, I think that storing the value would also be a nice alternative.
|
#6
|
|||
|
|||
Yeah, it may or may not make enough difference to worry about whether to have the db server do the actual counting or to do it in php, but storing it sidesteps the issue and avoids an extra query, so I'd probably do that. And you mentioned above adding it to the post table, but from what you said it sounds like the thread table would be better.
|
#7
|
||||
|
||||
Quote:
Quote:
|
#8
|
|||
|
|||
Quote:
If I understood you, you want the word count for the first post of a thread even if it's not being displayed on the current page? Then you'd either have to store that same count in each post of the thread or else always read the first post. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|