Any tips for speeding up PHP scripts..?

Want to chit chat about anything, do it here ... posting here won't increase your post count (or shouldn't!). Please do not post any "phpBB" specific topics here unless they do not fit into the category above. Do not post bug reports, feature or support requests!
Forum rules
Please do not post any "phpBB" specific topics here unless they do not fit into the category above.

Do not post bug reports, feature or support requests! No really... Do not post bug reports, feature or support requests! Doing so will make Bertie a very sad bear indeed. :(
Post Reply
ElbertF
Registered User
Posts: 583
Joined: Fri Dec 03, 2004 4:35 pm
Location: tracing..
Contact:

Any tips for speeding up PHP scripts..?

Post by ElbertF »

Since phpBB inspired me to start learning PHP, and eventually starting my own business as a programmer, I might aswell post this here.

I'm developing a CMS right now with a lot or functions similar to the ones used in phpBB, such as an advanced template parser, BBCode, search engine, etc.. I already integrated some functionality which I 'stole' from this new version in development. The devs here are way ahead of me though, they managed to keep the board up to speed by caching templates for instance.

Now I wonder, what can I do to speed up my scripts? What slows them down (although my average parse time is about the same as it is here)? Should I store image info in the DB and not in a file? Should I use less preg_replace() functions? Any ideas would be more then welcome!

Uchiha Nick
Registered User
Posts: 397
Joined: Tue Jul 20, 2004 6:21 am
Location: Rotterdam, The Netherlands
Contact:

Re: Any tips for speeding up PHP scripts..?

Post by Uchiha Nick »

first- reduce the total queries as much as you can.
second - preg_replace > str_replace, this simply replaces it immediately, str_replace first looks and then replaces. + Regex are sweet :) ( BBCode, Smilleys etc. )
third - caching is a good one, rather hard to apply correct though.
fourth - sessions, try to use the least possible amount of sessions. although this is better then cookies- cookies are evil itself !
fifth - OOP. object orientated programming- this cuts down a lot- since it only uses whats needed, nothing more and nothing less
sixth - try to create normalised databases ( whats it called in EN? ) relational etc.. LEFT and RIGHT joins
seventh - try not to overdo on total code- the more code thats required, the longer it takes. IE working with vars.

Code: Select all

// this method is a bit.. useless, since it takes up memory- which in turn takes speed
$var = $_POST['var'];
$_SESSION['var'] = $var;

// this method however- cuts back a little- but count each time you do this, and you [b]will[/b] notice quite a change
$_SESSION['var'] = $_POST['var'];

// only use the first method if you want to apply some functions to it

hope it helps :)
Image

Yawnster
Registered User
Posts: 342
Joined: Sat Jan 29, 2005 9:18 pm
Location: London, UK
Contact:

Re: Any tips for speeding up PHP scripts..?

Post by Yawnster »

http://www.lerdorf.com/tips.pdf" target="_blank
http://www.php.lt/benchmark/phpbench.php" target="_blank
http://phplens.com/lens/php-book/optimi ... ng-php.php" target="_blank

Just a few I have found rather useful...

Yawnster

ElbertF
Registered User
Posts: 583
Joined: Fri Dec 03, 2004 4:35 pm
Location: tracing..
Contact:

Re: Any tips for speeding up PHP scripts..?

Post by ElbertF »

Thanks, that's very useful :)

I didn´t find the article on phplens.com very useful (I´ve read it before), since my sites usually aren´t hosted on my own server and I don´t have any influence on that. But foreach() vs. while(list()=each()) etc. is pretty interesting :D

User avatar
Dog Cow
Registered User
Posts: 271
Joined: Wed May 25, 2005 2:14 pm

Re: Any tips for speeding up PHP scripts..?

Post by Dog Cow »

There are at least 2 different PHP accelerators that can be installed on a server. I'm not sure what they are called, but someone else may know.

ElbertF
Registered User
Posts: 583
Joined: Fri Dec 03, 2004 4:35 pm
Location: tracing..
Contact:

Re: Any tips for speeding up PHP scripts..?

Post by ElbertF »

Like Zend? Anyway, as I said I'm only interested in optimising my programming right now.. :)

uranusalien
Registered User
Posts: 32
Joined: Mon Oct 27, 2003 4:48 pm
Contact:

Re: Any tips for speeding up PHP scripts..?

Post by uranusalien »


shawMart
Registered User
Posts: 2
Joined: Mon Apr 24, 2006 3:56 pm

Re: Any tips for speeding up PHP scripts..?

Post by shawMart »

optimize that code! :-D
Image

Post Reply