Hello,
i think there are 3 possibilities
1) buggy PHP-Module, if you have an older module < 4.0.6 or an older Apache, think about an update if possible
2)
Apache caches some pages. Mark them as dynamic with metatags such as.
<meta http-equiv=\"expires\" content=\"allways\"><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">
3) use mysql_free_result() wherever possible
or/and cut your script into smaller pieces