在php中,内联<脚本>解决

In php, when will a inline <script> be resolved?

本文关键字:脚本 gt 解决 php lt 内联      更新时间:2024-06-13

我试图调试我的慢速php脚本,该脚本将查询提交给几个数据库和几个表,创建一个结果页面。

在php脚本中,我一开始就这样输入:

echo '<script>console.log("Start ",Date.now());</script>';

摘自《我如何用PHP编写控制台?》?

php脚本末尾也有类似的内容。

但是,由于我需要30到1分钟才能得到结果页面,因此从firebug控制台中打印的脚本开始到结束的时间差不到一秒钟。

像这样:

启动1460618023753

结束1460618023923

所以我想我误解了这些内联实际上是在什么时候运行的。

有人能解释为什么会这样吗?也许可以建议我原则上如何调试php代码的慢部分?

要在php中测量时间,需要使用php代码。

开始运行时:

$start = time();

最终使用

$duration = time() - $start;
echo '<script>console.log("Duration ",' . $duration . ');</script>';

您也可以回显Start和End,但需要使用php时间:

echo '<script>console.log("Start ",' . time() . ');</script>';

echo '<script>console.log("End ",' . time() . ');</script>';