• Welcome to NamesLot.com Domain Name Forum

    NamesLot.com Domain Name Forum offers a fully open forum to discuss domain industry news and a 0% commission marketplace for you to buy and sell domain names.

    We have reorganized our Marketplace so now it is easier to get attention to your domain while it is also easier for buyers to find the right domain name.

    If you want us to add more threads to our marketplace, please contact us! Listing on our marketplace as always, 100% free! Register NOW or Login HERE!

Making php faster

  • Thread starter Thread starter nick
  • Start date Start date
Status
Not open for further replies.
N

nick

Guest
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.
 
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.
 
How about gzip compression. Does it makes it faster? I have heard it compresses the data saving lots of time and bandwidth.
 
what about this two function

MySql_connect()
MySql_pconnect() // persistence connection

which one is batter and advisable to use.
 
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.
 
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.persistent-connections.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:
 
Status
Not open for further replies.

Members online

No members online now.

Forum statistics

Threads
19,801
Messages
69,798
Members
44,585
Latest member
tsscgroup
Active members today
0
New members today
0
New threads today
2
New posts today
2

Follow NamesLot on Twitter!

NamesLot proudly supported by

NamesLot proudly supported by

Top