什么东西可以使PHP脚本变慢? [关闭]

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.

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";

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.