Hi Guys, Just wondering.. Why is it that when you ( mysql -uUSERNAME -pPASSWORD ) and then run a query. Its like UBER quick and uses hardly any CPU.. ( 0.00 sec ) However the same query thats run through PHP takes like 1second and uses 99% cpu when it happens? Ive just noticed this and wonders if these some odd setting in php misconfigured? Thanks
It's tough to answer this question. You first need to benchmark the php script to see where the bottleneck is. It could be the query, but it could also be outputting to the browser or some other php process. Generally, the speed of a query run from command line should be roughly equivalent to the speed of a query run from php or any other program. The time differences would occur where php has to process additional logic or render to the browser. If the database is not on the same server as the website, there is definitely going to be latency in communicating with the database server.
try to run your query from command prompt ( or shell ) ... if it runs faster then u know that its browser rendering that uses cpu