Re: Help - need to quickly optimize a record count!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Brian Dunning <brian@xxxxxxxxxxxxxxxx>:
> I am cross-posting this to the PHP and the MySQL lists because I'm  
> not sure in which technology my solution will lie.
>
> I have a pretty busy PHP/MySQL site that executes the following query  
> a lot:
>
> select count(*) as `count` from terms;
>
> My MySQL account was disabled by my ISP because this query was  
> causing resource issues, so I need to find a different way to know  
> the record count in that table. A few records are added once every 5  
> minutes by a cron job. The record count is constant the rest of the  
> time. No records are ever deleted.
>
> Is it possible to create some kind of server-side variable, in which  
> the cron job could store the record count, which would be accessible  
> to all scripts, and would stay the same until it gets reset? Or is  
> there a less-intense MySQL query I should be using instead?

If the cron job is running anyways, you could run the count query after
updating, and then store the count in a file. Then have your scripts
read from that file. You could also store the count in the database. 

Another possibility is to run the count once, and then each time you add
records, add the count of new records to that count. Again, storage
could be in either a file or a DB.

Either way, you're down to doing the count at most 12 times per hour,
instead of every time your scripts are hit.

-- 
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux