duanji2002 2010-09-25 16:34
浏览 71
已采纳

将调试内容输出到文件中的最简单方法

I've got an applicaiton with various php scripts. I want to get an idea of how much time it takes for the execution to move from one point to another (there are many such points).

I was looking for a simple php line that I can insert without modification, at different spots in my code and get an output file (NOT generated html) which shows something like:

FILENAME      FUNCTION        LINENUMBER      TIMESTAMP

I've started using this:

file_put_contents('/home/default/public_html/debug.log',  __FILE__ . "\t" .
 __FUNCTION__ . "\t" . __LINE__ . "\t" . microtime(true)."
", FILE_APPEND);

which is good, but are there better ways of doing the same?

  • 写回答

2条回答 默认 最新

  • douliang1900 2010-09-25 16:41
    关注

    For a simple way to do this, you can either use the global PHP error system with trigger_error() and a E_NOTICE level, or the error_log() function to log in a separate file.

    I your case I would recommend the second solution.


    With the trigger_error():

    <?php
        trigger_error("Call will start now", E_NOTICE);
        startTheHugeCall();
        trigger_error("Call is finished", E_NOTICE);
    ?>
    

    With the error_log() :

    <?php
        error_log("Call will start now", 3, "/var/tmp/debugfile.log");
        startTheHugeCall();
        error_log("Call is finished", 3, "/var/tmp/debugfile.log");
    ?>
    

    Resources :

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题