PHP性能 [英] PHP performance

查看:63
本文介绍了PHP性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不在服务器上安装软件的情况下提高PHP脚本的性能/速度?

What can I do to increase the performance/speed of my PHP scripts without installing software on my servers?

推荐答案

配置文件.轮廓.轮廓.我不确定是否有PHP可用的东西,但是编写一个小工具以在代码中插入概要分析信息应该很简单.您将需要分析函数时间和SQL查询时间.

Profile. Profile. Profile. I'm not sure if there is anything out there for PHP, but it should be simple to write a little tool to insert profiling information in your code. You will want to profile function times and SQL query times.

那么在哪里有功能:

function foo($stuff) {
    ...
    return ...;
}

我将其更改为:

function foo($stuff) {
    trace_push_fn('foo');
    ...
    trace_pop_fn('foo');
    return ...;
}

(这是函数中多次返回成为障碍的情况之一.)

(This is one of those cases where multiple returns in a function become a hinderance.)

和SQL:

function bar($stuff) {
    trace_push_fn('bar');

    $query = ...;
    trace_push_sql($query);
    mysql_query($query);
    trace_pop_sql($query);

    trace_pop_fn('bar');
    return ...;
}

最后,您可以生成程序执行的完整跟踪,并使用各种技术来识别瓶颈.

In the end, you can generate a full trace of the program execution and use all sorts of techniques to identify your bottlenecks.

这篇关于PHP性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆