-5

I need to know what kind of things can make a php script slow.

things like:

function test()
{
$out = 'cont';
$out .= 'cont2';
$out .= 'cont3';
return $out;
}
echo test();

or

function test($t)
{
$out = ($t)?'v1':'v2';
return $out;
}
echo test(1);

is there some link where i can find it?

thanks.

  • 1
    Why would either of those functions make the script slow? – Paul Dessert Apr 18 '12 at 23:22
  • 2
    `sleep(500)`? that would make a script slow. – Jonathan Kuhn Apr 18 '12 at 23:25
  • 1
    Why do you care? Is your script slow? If not, don't bother. If it is, just use a profiler. – netcoder Apr 18 '12 at 23:28
  • Have a look here: http://stackoverflow.com/questions/4195937/what-are-some-good-php-performance-tips. Is that what you wanted to know? Otherwise, please clarify what exactly you are wondering. – Armatus Apr 18 '12 at 23:32
  • My scripts aren't slow but alot of peoples will use it, my database is ok but i'm a bit care about alot of peoples using my system. then i'll like to know somethings to get a better performance. – Rafael Osvaldo Apr 18 '12 at 23:35
  • That's a very generic question: "how can I get better performance from my code"... The generic answer is "less code equals less problems". It's way too vague to expand on it. You know, generic coding guidelines: don't write in 10 lines what you can do in 1... and so on... – netcoder Apr 18 '12 at 23:44

2 Answers2

0

Your question is vague, but you can benchmark them yourself:

$start = microtime(true);
// code you want to benchmark here
$diff = microtime(true) - $start;
echo "Code execution lasted $diff seconds";
QuantumBlack
  • 1,549
  • 11
  • 27
0

Its not simple to answer this question given its generic nature, but let me give a try.

While you can worry about changing double quotes to single quotes, not using string concatenation, etc. and micro-optimizing a lot of these, usually the long poll is either a DB or a HTTP request (web services, etc.)

So, you would need to think about caching, etc. (server-side PHP.) But that also would have implications with respect to how to bust caching, etc., that's a different problem altogether.

To generally speed up PHP you could use one of the opcode caching engines like APC. Many of the popular sites including Facebook, Yahoo! use it.

You can use APD or Xdebug to figure out where your script is taking time.

If you are still worried about PHP's performance and not satisfied you could take a look at Hip-Hop, or move some of your business critical operations to C/C++ by having extensions and so forth.

If you are worried about page performance, 80% of the problem lies in the front-end so try to optimize your HTML, CSS, and JavaScript by checking your page against YSlow, Google PageSpeed, etc.

Hope that helps.

g13n
  • 3,218
  • 2
  • 24
  • 19