Post Reply  Post Thread 

Making php faster
Author Message
nick
SEO Dictator

SEO Team

Posts: 1,177
Group: SEO Team
   
Cash: 432.01 Donate
Making php faster

I have been programming since 2001 first using VB and now using PHP

But in every language I have seen some functions and some loops are far slower then the others which can produce the same results.

Let me list some of them and if you have some ideas about others then please list them too.

First of all.

A Switch is faster then multiple IF's

Then comes the Loops

Ordered from fastest to slowest ones.

FOR Loop
While Loop
Do-While Loop
Foreach Loop

Now comes the use of arrays rather then defining number of variables inside some loop.

For example if you have a loop from 1 to 100 and you are assigning values to 100 varibales then use array here. and then walk through that array with help of some other loop if needed or directly access its value at some point in the code flow.


DNDaily.com - Your Daily Domain Doze
Twut.com - Free Online Games
Product reviews and ratings
Search Engine Optimization Packages
03-04-2007 11:16 PM
Send the author a private message Find all posts by this author Quote this message in a reply

Advertisements

This is an ad revenue sharing forum
Nameslot
Administrator

Administrators

Posts: 1,503
Group: Administrators
   
Cash: 700.50 Donate
RE: Making php faster

I use mt_rand() function instead of rand() function in php for rqandom number generation for showing different banners on the top of our forums.


Nameslot.com | Do you have a question? shoot me a PM.
03-05-2007 12:57 AM
Send the author an email Send the author a private message Visit authors website Find all posts by this author Quote this message in a reply
jayesh
Moderator

Moderators

Posts: 531
Group: Moderators
   
Cash: 141.50 Donate
RE: Making php faster

How about gzip compression. Does it makes it faster? I have heard it compresses the data saving lots of time and bandwidth.


General Articles | Online Marketing Blog |Finance Directory|Rehearsal Dinner
04-06-2007 09:21 PM
Send the author a private message Visit authors website Find all posts by this author Quote this message in a reply
jignesh
Moderator

Moderators

Posts: 363
Group: Moderators
   
Cash: 307.00 Donate
RE: Making php faster

what about this two function

MySql_connect()
MySql_pconnect() // persistence connection

which one is batter and advisable to use.


Technical Information | Technical World | Seo Services india | BizComSoft
04-06-2007 09:37 PM
Send the author an email Send the author a private message Find all posts by this author Quote this message in a reply
nick
SEO Dictator

SEO Team

Posts: 1,177
Group: SEO Team
   
Cash: 432.01 Donate
RE: Making php faster

Depends lets say if the script is running and some 1000 hits are thrown on it. And the person goes from page to page then this connections are established in multiples of 1000's as they go on...

If you make it persistent then the 1000 threads ( channels of connections ) are established as are loaded in the memory which can be resource intensive and sometimes can give an error if the server does not allows more then some smaller number of connections to the MySQL server.


DNDaily.com - Your Daily Domain Doze
Twut.com - Free Online Games
Product reviews and ratings
Search Engine Optimization Packages
04-07-2007 12:28 AM
Send the author a private message Find all posts by this author Quote this message in a reply
maximum
Super Moderator

Super Moderators

Posts: 35
Group: Super Moderators
   
Cash: 0.00 Donate
RE: Making php faster

Nameslot,
mt_rand() versus rand() - as of PHP 4.2.0 (this site uses PHP 5.1.2) there is no longer a need for the slower use of mt_rand(). It seeds (makes unique with variable calculation) the random number generator. As of PHP 4.2.0, this is done automatically with just rand(). Save time and resources, if you care to, by just using rand()

Jayesh,

It can definately make things faster for the user's browser to receive it and save on bandwidth. GZip-compression can be either done via .htaccess or server-wide. An example is this exact forum page/thread (prior to me posting my reply:tongue: ) :

Size (original) in bytes: 38,020
Size (compressed) in bytes: 6,401
Compression: 83.2% (about average for this forum's pages, based off server settings)
Now, 38,020-bytes versus 6,401-bytes - something your browser, your internet connection speed, and Nameslot.com's bandwidth can all appreciate:grin:

Nick,
Good points:grinning-wink:
http://us.php.net/manual/en/features.per...ctions.php
As to your original post: Worst enemy of speed....Poor syntax and the simple things like unneccessary whitespace, several calls to the same DB connection when one will do storing values for later use, run a function inside a function inside another (nesting), ect. PLAN out a diagram, like a blueprint, and make sure you are not taking needless steps in your code:wink:

This post was last modified: 07-20-2007 10:38 AM by maximum.

07-20-2007 10:23 AM
Send the author a private message Find all posts by this author Quote this message in a reply

Post Reply  Post Thread 


View a Printable Version | Send this Thread to a Friend | Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:
Forum Jump: