Site running slow... pls help

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
laics
Forum Newbie
Posts: 7
Joined: Mon Apr 07, 2008 2:21 pm

Site running slow... pls help

Post by laics »

Dear all,

I have just uploaded my files to hostinghogator. However then only i realise that my code is running really slow when i access to my page. The execution delayed each time it encountered to functions which are to retrieve and display info. Can you please advice me any method to make my php scripts run faster? it took nearly 30 sec to load my home page eventhough I have apply gzip compression, javascript compression.. Please advice...
Thanks..
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Site running slow... pls help

Post by pickle »

We're going to need to know WAAAAYY more before we can tell you how to optimize your scripts.

The best way you can do it yourself is to put: echo microtime() all throughout your scripts. This will echo the current time with microseconds to the screen. Examining this output can help you figure out which parts of your scripts are running slow.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: Site running slow... pls help

Post by arjan.top »

xdebug profiling is the way to go

http://xdebug.org/docs/profiler
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: Site running slow... pls help

Post by matthijs »

Have you tested your code locally? That way you know if it's the server or not. Sometimes (shared) servers can be very slow. There are huge differences between hosting providers.
laics
Forum Newbie
Posts: 7
Joined: Mon Apr 07, 2008 2:21 pm

Re: Site running slow... pls help

Post by laics »

Dear matthijs, thanks for the reply. I have tested the code locally and it just work fine. It is since I uploaded my code to the server then only I encountered such a slow speed. This is the reason I am trying to change some of my initial code and see whether there's improvement. Any comment? Tq..
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: Site running slow... pls help

Post by matthijs »

Ok, then it is possible that it's just the server of the host. If you have access to other hosting you could try that.

I have just cancelled a Dreamhost account because the server was so slow.

And, as others suggested, you can test your code with xDebug or microtime. If you know it runs fast locally, it must be the server. And optimizing the code doesn't make sense then.
laics
Forum Newbie
Posts: 7
Joined: Mon Apr 07, 2008 2:21 pm

Re: Site running slow... pls help

Post by laics »

Is it possible to run xDebug on shared host? If can may I know how to do so? thanks
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: Site running slow... pls help

Post by arjan.top »

why would you do that?

Parts of the code that are slow are slow on localhost too
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: Site running slow... pls help

Post by matthijs »

If your code runs in 0.4 seconds locally, and it takes 30 seconds to load your page on the host, it will not change anything if you manage to change your code to run in .35 seconds.
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: Site running slow... pls help

Post by arjan.top »

Damn missed the post that script works fine locally

Then yes, find another host :D
Post Reply