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?/archives/28-How-long-is-a-piece-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


.



Relevant Pages

  • Re: email address for signup in php
    ... This is test code as I'm beginner PHP guy. ... echo $email_address.$newline; ... you need to understand how SQL in general works. ... strings used in SQL requests need to be enclosed by single quotes. ...
    (comp.lang.php)
  • Re: Name of the day in different languages.
    ... > Luigi Donatello Asero wrote: ... or are both all right for php? ... As to the quotes, ... When can I use a comma between echo and strftime? ...
    (alt.php)
  • Re: Proper Way to Use [while] Loops
    ... I'm new to PHP and am trying to create a template from the ... set up a loop to post every item on the newspost table. ... // START MARKUP ... Using double quotes in a string enclosed with single quotes requires no escaping and vica versa. ...
    (alt.php)
  • RE: [PHP] Cannot send a hyperlink
    ... Yes you do not need quotes in the mailfunction. ... [PHP] Cannot send a hyperlink ... Your problem is the Headers are missing which allows the html content to ...
    (php.general)
  • Re: nesting JS in echos
    ... from html to php. ... the conversion went well, it was to use a php session cookie to stop the ... single quotes and double quotes needed in the doc.write and variable ... my mistake was to leave the image path in single quotes; ...
    (comp.lang.php)