Bluehost.com Web Hosting $6.95

Optimized PHP

This is a discussion on Optimized PHP within the PHP General forums, part of the PHP Programming Forums category; Hello All, I am working on PHP from quite some time. I am pretty much comfortable in writing PHP code ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-03-2007
ashish.sharma
 
Posts: n/a
Default Optimized PHP


Hello All,

I am working on PHP from quite some time. I am pretty much comfortable in
writing PHP code but I always want that I should write good, quality code.
For this I always look for the best practices which other developers uses
and implement and I am writing this for the same reason as I would like to
know how can i code a good, optimized PHP code. What are the areas where I
can optimize my code more to avoid extra consumption of resources h/w or
s/w. What are the best practices I can follow to optimize my code to
increase the speed and performance of my application and to reduce down the
memory consumption. For example ..

In an application where I am having some different settings for each of the
user/visitor, then what will be the best approach of doing this? Should I
keep all the settings in sessions or should i create an xml/ini file for
each user and call that in the bootstrap file (at runtime, on the basis of
the the User) to pick the settings of that user.

These are the kind of questions for which I always have to think. So, can
anyone suggest me some source / article / reference from where I can find
the solutions of such of my problems.

Looking forward for your suggestions ..

Thx to all ..

Ashish
--
View this message in context: http://www.nabble.com/Optimized-PHP-...html#a13013016
Sent from the PHP - General mailing list archive at Nabble.com.

Reply With Quote
  #2 (permalink)  
Old 10-03-2007
Larry Garfield
 
Posts: n/a
Default Re: [PHP] Optimized PHP

First rule: Premature optimization is the root of all evil. Don't try to
squeeze every millisecond out of your code unless it really needs it.

That said, the conventional place to stick user account data is in the
database. The exact schema will vary, but you will want some sort of unique
user id, a login name, a password, and "other stuff".

For tracking active visitors, that's what the session is for. Only store
information in the session that should be persistent only for one visit.
That will probably include the active user id plus whatever else you need.

You also probably don't want to use the default session save handling, as it
is not very robust. Instead, write your own session handling functions and
save the session data to the database. That will give you better security, a
more robust and extensible system, and in some cases even a performance
boost. See:

http://www.php.net/manual/en/functio...ve-handler.php

On Wednesday 03 October 2007, ashish.sharma wrote:
> Hello All,
>
> I am working on PHP from quite some time. I am pretty much comfortable in
> writing PHP code but I always want that I should write good, quality code.
> For this I always look for the best practices which other developers uses
> and implement and I am writing this for the same reason as I would like to
> know how can i code a good, optimized PHP code. What are the areas where I
> can optimize my code more to avoid extra consumption of resources h/w or
> s/w. What are the best practices I can follow to optimize my code to
> increase the speed and performance of my application and to reduce down the
> memory consumption. For example ..
>
> In an application where I am having some different settings for each of the
> user/visitor, then what will be the best approach of doing this? Should I
> keep all the settings in sessions or should i create an xml/ini file for
> each user and call that in the bootstrap file (at runtime, on the basis of
> the the User) to pick the settings of that user.
>
> These are the kind of questions for which I always have to think. So, can
> anyone suggest me some source / article / reference from where I can find
> the solutions of such of my problems.
>
> Looking forward for your suggestions ..
>
> Thx to all ..
>
> Ashish



--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
Reply With Quote
  #3 (permalink)  
Old 10-03-2007
Cameron Just
 
Posts: n/a
Default Re: [PHP] Optimized PHP

One trick that one of my friends has taught me is to only use double
quotes "s where needed as they are parsed by PHP and instead use single
quotes 's

i.e.
$fred['john'] = 10;
is better than
$fred["john"] = 10;

or
echo 'This is some text' . "\n";
instead of
echo "This is some text\n";

He told me that everything within double quotes must be walked through
by PHP looking for variables or other escaped characters. Since most
code has these style statements every few lines the overall time saved
adds up.

ashish.sharma wrote:
> Hello All,
>
> I am working on PHP from quite some time. I am pretty much comfortable in
> writing PHP code but I always want that I should write good, quality code.
> For this I always look for the best practices which other developers uses
> and implement and I am writing this for the same reason as I would like to
> know how can i code a good, optimized PHP code. What are the areas where I
> can optimize my code more to avoid extra consumption of resources h/w or
> s/w. What are the best practices I can follow to optimize my code to
> increase the speed and performance of my application and to reduce down the
> memory consumption. For example ..
>
> In an application where I am having some different settings for each of the
> user/visitor, then what will be the best approach of doing this? Should I
> keep all the settings in sessions or should i create an xml/ini file for
> each user and call that in the bootstrap file (at runtime, on the basis of
> the the User) to pick the settings of that user.
>
> These are the kind of questions for which I always have to think. So, can
> anyone suggest me some source / article / reference from where I can find
> the solutions of such of my problems.
>
> Looking forward for your suggestions ..
>
> Thx to all ..
>
> Ashish
>

Reply With Quote
  #4 (permalink)  
Old 10-03-2007
Zoltán Németh
 
Posts: n/a
Default Re: [PHP] Optimized PHP

2007. 10. 3, szerda keltezéssel 16.07-kor Cameron Just ezt Ã*rta:
> One trick that one of my friends has taught me is to only use double
> quotes "s where needed as they are parsed by PHP and instead use single
> quotes 's
>
> i.e.
> $fred['john'] = 10;
> is better than
> $fred["john"] = 10;
>
> or
> echo 'This is some text' . "\n";
> instead of
> echo "This is some text\n";
>
> He told me that everything within double quotes must be walked through
> by PHP looking for variables or other escaped characters. Since most
> code has these style statements every few lines the overall time saved
> adds up.
>


AFAIK that's not absolutely true.
First, every string must be checked over for escaped characters and such
- not only those within double quotes.
Second, the opcode for double quotes differ only if they contain
variables:
http://blog.libssh2.org/index.php?/a...of-string.html

and anyway, the microseconds you could win with this really don't count
that much to be worth the effort... find real bottlenecks and optimize
against those.

greets
Zoltán Németh

> ashish.sharma wrote:
> > Hello All,
> >
> > I am working on PHP from quite some time. I am pretty much comfortable in
> > writing PHP code but I always want that I should write good, quality code.
> > For this I always look for the best practices which other developers uses
> > and implement and I am writing this for the same reason as I would like to
> > know how can i code a good, optimized PHP code. What are the areas where I
> > can optimize my code more to avoid extra consumption of resources h/w or
> > s/w. What are the best practices I can follow to optimize my code to
> > increase the speed and performance of my application and to reduce down the
> > memory consumption. For example ..
> >
> > In an application where I am having some different settings for each of the
> > user/visitor, then what will be the best approach of doing this? Should I
> > keep all the settings in sessions or should i create an xml/ini file for
> > each user and call that in the bootstrap file (at runtime, on the basis of
> > the the User) to pick the settings of that user.
> >
> > These are the kind of questions for which I always have to think. So, can
> > anyone suggest me some source / article / reference from where I can find
> > the solutions of such of my problems.
> >
> > Looking forward for your suggestions ..
> >
> > Thx to all ..
> >
> > Ashish
> >

>

Reply With Quote
  #5 (permalink)  
Old 10-03-2007
Per Jessen
 
Posts: n/a
Default Re: [PHP] Optimized PHP

Zoltán Németh wrote:

> and anyway, the microseconds you could win with this really don't
> count that much to be worth the effort... find real bottlenecks and
> optimize against those.


And finally, if you're worried about microseconds, why are you using an
interpreted language?


/Per Jessen, Zürich
Reply With Quote
  #6 (permalink)  
Old 10-03-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] Optimized PHP

On 10/3/07, ashish.sharma <ashish.sharma@vinove.com> wrote:
>
>
> Hello All,
>
> I am working on PHP from quite some time. I am pretty much comfortable in
> writing PHP code but I always want that I should write good, quality code.
> For this I always look for the best practices which other developers uses
> and implement and I am writing this for the same reason as I would like to
> know how can i code a good, optimized PHP code. What are the areas where I
> can optimize my code more to avoid extra consumption of resources h/w or
> s/w. What are the best practices I can follow to optimize my code to
> increase the speed and performance of my application and to reduce down
> the
> memory consumption. For example ..
>
> In an application where I am having some different settings for each of
> the
> user/visitor, then what will be the best approach of doing this? Should I
> keep all the settings in sessions or should i create an xml/ini file for
> each user and call that in the bootstrap file (at runtime, on the basis of
> the the User) to pick the settings of that user.
>
> These are the kind of questions for which I always have to think. So, can
> anyone suggest me some source / article / reference from where I can find
> the solutions of such of my problems.
>
> Looking forward for your suggestions ..
>
> Thx to all ..
>
> Ashish
> --
> View this message in context:
> http://www.nabble.com/Optimized-PHP-...html#a13013016
> Sent from the PHP - General mailing list archive at Nabble.com.
>



one nice trick you can easily implement is to compress your code before
pushing it to production.
the php cli exposes a method for stripping out the whitespace and comments.

php -w

-nathan

Reply With Quote
  #7 (permalink)  
Old 10-03-2007
Robert Cummings
 
Posts: n/a
Default Re: [PHP] Optimized PHP

On Wed, 2007-10-03 at 09:52 -0400, Nathan Nobbe wrote:
>
> one nice trick you can easily implement is to compress your code before
> pushing it to production.
> the php cli exposes a method for stripping out the whitespace and comments.
>
> php -w


Do it right, use a compile cache like Eaccelerator or APC.

Cheers,
Rob.
--
.................................................. ..........
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
.................................................. ..........
Reply With Quote
  #8 (permalink)  
Old 10-03-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] Optimized PHP

On 10/3/07, Robert Cummings <robert@interjinn.com> wrote:
>
> On Wed, 2007-10-03 at 09:52 -0400, Nathan Nobbe wrote:
> >
> > one nice trick you can easily implement is to compress your code before
> > pushing it to production.
> > the php cli exposes a method for stripping out the whitespace and

> comments.
> >
> > php -w

>
> Do it right, use a compile cache like Eaccelerator or APC.
>
> Cheers,
> Rob.
> --
> .................................................. .........
> SwarmBuy.com - http://www.swarmbuy.com
>
> Leveraging the buying power of the masses!
> .................................................. .........
>


of course i use the caching engines as well, but for people who dont
want to use a caching engine or arent allowed to, i think this is a great
strategy. especially since php facilitates it out of the box.
another benefit is less disk space on the production system for the code.
and even when using a compile cache, the first time the script is
interpreted
it will take less time to read in the source (oh i guess were getting into
milliseconds
again [heh]).

-nathan

Reply With Quote
  #9 (permalink)  
Old 10-03-2007
Robert Cummings
 
Posts: n/a
Default Re: [PHP] Optimized PHP

On Wed, 2007-10-03 at 10:22 -0400, Nathan Nobbe wrote:
> On 10/3/07, Robert Cummings <robert@interjinn.com> wrote:
> >
> > On Wed, 2007-10-03 at 09:52 -0400, Nathan Nobbe wrote:
> > >
> > > one nice trick you can easily implement is to compress your code before
> > > pushing it to production.
> > > the php cli exposes a method for stripping out the whitespace and

> > comments.
> > >
> > > php -w


> >
> > Do it right, use a compile cache like Eaccelerator or APC.
> >


> of course i use the caching engines as well, but for people who dont
> want to use a caching engine or arent allowed to, i think this is a great
> strategy. especially since php facilitates it out of the box.
> another benefit is less disk space on the production system for the code.
> and even when using a compile cache, the first time the script is
> interpreted
> it will take less time to read in the source (oh i guess were getting into
> milliseconds
> again [heh]).


More likely a microsecond issue :)

Cheers,
Rob.
--
.................................................. ..........
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
.................................................. ..........
Reply With Quote
  #10 (permalink)  
Old 10-03-2007
Al
 
Posts: n/a
Default Re: Optimized PHP

Advanced PHP Programming, Geo. Schlossnagle

Discusses large-scale, optimized websites in great detail

ashish.sharma wrote:
> Hello All,
>
> I am working on PHP from quite some time. I am pretty much comfortable in
> writing PHP code but I always want that I should write good, quality code.
> For this I always look for the best practices which other developers uses
> and implement and I am writing this for the same reason as I would like to
> know how can i code a good, optimized PHP code. What are the areas where I
> can optimize my code more to avoid extra consumption of resources h/w or
> s/w. What are the best practices I can follow to optimize my code to
> increase the speed and performance of my application and to reduce down the
> memory consumption. For example ..
>
> In an application where I am having some different settings for each of the
> user/visitor, then what will be the best approach of doing this? Should I
> keep all the settings in sessions or should i create an xml/ini file for
> each user and call that in the bootstrap file (at runtime, on the basis of
> the the User) to pick the settings of that user.
>
> These are the kind of questions for which I always have to think. So, can
> anyone suggest me some source / article / reference from where I can find
> the solutions of such of my problems.
>
> Looking forward for your suggestions ..
>
> Thx to all ..
>
> Ashish

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:06 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0