Well all these answers as well as closing votes are just trash.
I can't believe such ignorance and guesswork can be ever exist.
This is perfectly legitimate programming question, however poorly asked and even worst answered.
Imagine you are sick and come to doctor.
- A am sick! - says you - Give me something.
Doesn't it scare you if doctor would give you some drugs, without any diagnostics?
Just in case, thinking, "It helped some person and may be help this one". Doesn't is sound weird?. But you all here acting exactly the same way!
But it shouldn't be this way.
One have to investigate first, give a diagnosis, and only then order treatment.
Every damned one here have to learn what profiling is.
And speak of nothing but profiling.
You have to investigate, what particular reason causing such performance impact.
Every answer here should be teaching you how to do that.
40 seconds is awful lot of time, no "fine tuning" recipes can help. There is some serious misconfiguration somewhere. But a web-server is not a single system. it consists of many parts - database, web-server, programming code, static files, etc. So, you have to find certain part that causing such slowness. Only then you can ask for certain treatment.
So, first of all you have to be certain - what page load slow? What does it do? What parts of it runs slow? Using
microtime(1) function you can measure tume consuming by various parts of this page. So, you can locate problem part. And so on.
You can consult here about all these steps, but you have to give all possible feedback, not just asking
I am sick, give me cure My server is slow, what to do.