View Full Version : mysql_free_result(), is it needed here?

11-01-2003, 01:50 AM
ok, im writing a big script for my own site and also for someone else's site, and im trying to make it as fast as possible. It has a template system, and currently uses 19 database tables. Its basically a CMS system, but with a few extra things specific to our sites.

ok, so i need speed. Its currently 600 lines and im about 10% done in terms of functionality. Im averaging about 5 queries per page, some more, some less.

Everything is split into functions, within a class. When i query, it is always within a function. what i want to know is, do i need to use mysql_free_result() to clear the query data (which would speed it up a bit) within the function, or is the data lost at the end of the function?

11-01-2003, 02:46 AM
I wouldn't count too much on mysql_free_result() to bring great speed improvement, if you're not pulling out absurd quantities of data from your database. If I understood you correctly, you described the generation of one standard page in that CMS - correct? If so, I wouldn't worry about the 5 queries. It won't affect you negatively, though. Just make sure you don't free the result sets too soon.

If you think that your app is going too slow, then better benchmark it with PEAR::Benchmark or the sample code on the manual page for microtime(). Once you know exactly at what point of execution the app slows down, you can concentrate on fine-tuning it where the need actually is. Maybe the connection to the database is more time-consuming, who knows? Get some hard numbers and let them say where and what to optimize.

11-01-2003, 02:49 AM
And regarding your last question: The memory allocated for the result sets will be freed upon the end of the script, not the end of the function using it.

11-01-2003, 02:53 AM
thanks for the advice mordred.

The cms is running quite smoothly on my local server, i have a 256MB ram and the templates are being parsed for about 50 sections and data loaded in 50 milliseconds (depending what page). Im quite pleased with that.

What i was also thinking about, is the administration where mass lists and data may need to be loaded for certain tasks. not just to speed up the script, but not abuse the server :p.

thanks for your advice, i will get some better figures and decide whats best.