php打开页面就加载语句,是否过度使用php echo语句会使页面加载时间变慢(Does extensive use of php echo statement make page load time...

是否过度使用php echo语句会使页面加载时间变慢(Does extensive use of php echo statement make page load times slower?)

我知道之前已经问过这个问题,但我找不到明确的答案。

过度使用echo语句会减慢最终用户加载时间吗?

通过在文件中包含更多的echo语句,文件大小会增加,所以我知道这将是一个因素。 如我错了请纠正我。

我知道经过一些研究后使用php的ob_start()函数以及upping Apaches SendBufferSize可以帮助减少加载时间,但据我所知,这更多是通过允许php更快地完成/退出来减少php执行时间,这反过来允许Apache更快退出。

话虽如此,php确实会更快退出,但这是否意味着php实际上花费的时间更少,从而加快了最终用户端的速度?

要清楚,我的意思是,如果我有两个文件,相同的内容,一个使用echo语句为每个html标签和另一个文件使用标准的方法进入和退出PHP,除了文件大小与echo语句的“过度”使用有什么不同(我猜的原因是什么?)哪一个会更快? 或者真的没有任何区别吗?

也许我正在谈论这个或者看错了?

编辑:我已经做了一些检查,并找到了一种方法来创建一个秒表来检查脚本的执行时间,似乎工作退出很好。 如果有人有兴趣这样做,那么链接到我现在选择使用的方法。

I know this question has been asked before but I haven't been able to find a definitive answer.

Does the overly use of the echo statement slow down end user load times?

By having more echo statements in the file the file size increases so I know this would be a factor. Correct me if I'm wrong.

I know after some research that using php's ob_start() function along with upping Apaches SendBufferSize can help decrease load times, but from what I understand this is more of decrease in php execution time by allowing php to finish/exit sooner, which in turn allows Apache to exit sooner.

With that being said, php does exit sooner, but does that mean php actually took less time to execute and in turn speed things up on the end user side ?

To be clear, what I mean by this is if I had 2 files, same content, and one made use of the echo statement for every html tag and the other file used the standard method of breaking in and out of php, aside for the difference in file size from the "overly" use of the echo statement (within reason I'm guessing?), which one would be faster? Or would there really not be any difference?

Maybe I'm going about this or looking at this wrong?

Edit: I have done a bit of checking around and found a way to create a stop watch to check execution time of a script and seems to work quit well. If anybody is interested in doing the same here is the link to the method I have chosen to use for now.

原文:https://stackoverflow.com/questions/14125402

更新时间:2019-12-13 15:12

最满意答案

过度使用echo语句会减慢最终用户加载时间吗?

没有。

通过在文件中包含更多的echo语句,文件大小会增加,所以我知道这将是一个因素。 如我错了请纠正我。

你错了。

这是否意味着PHP实际上花了更少的时间来执行,反过来加快了最终用户端的速度?

没有。

或者真的没有任何区别吗?

是。

也许我正在谈论这个或者看错了?

当然。

与性能相关的问题存在共同的问题。

他们中的大多数人不是出于真正的需要,而是出于想象。

虽然人们必须解决实际问题,而不是可以想象的问题。

Does the overly use of the echo statement slow down end user load times?

No.

By having more echo statements in the file the file size increases so I know this would be a factor. Correct me if I'm wrong.

You are wrong.

does that mean php actually took less time to execute and in turn speed things up on the end user side?

No.

Or would there really not be any difference?

Yes.

Maybe I'm going about this or looking at this wrong?

Definitely.

There is a common problem with performance related questions.

Most of them coming up not from the real needs but out of imagination.

While one have to solve only real problems, not imaginable ones.

2013-01-02

相关问答

并且=被称为短开放标签,并且始终不能使用PHP 5.3或更低版本(请参阅short_open_tag伪指令)(但是由于PHP 5.4.0, =始终可用)。 实际上,在PHP 5.3.0提供的php.ini生产文件中,它们默认是禁用的: $ grep 'short_open' php.ini-production

; short_open_tag

short_open_tag = Off

因此,在您想要分发的应用程序中使用它们可能不是一个好主意:如果您的应用程序未启用,您的应用程序将

...

你必须在html标签内转义双引号或使用单引号。 现在,echo认为它在"

";

要么 echo '

';

要么 echo "

";

You have to escape double quotes inside html tags or use single quotes. Right now, echo thi

...

第一个代码片段产生了这个Zend代码: ECHO '%3Cp%3EHello+welcome+to+my+site%3C%2Fp%3E%0A%3Cp%3EYour+name+is+'

ECHO !0

ECHO '%21%3C%2Fp%3E%0A%3Cp%3EYour+age+is+'

ECHO !1

ECHO '%21%3C%2Fp%3E%0A%3Cp%3EYour+email+address+is+'

ECHO !2

...

关于变量变量在这里阅读 $displayCode = 'num_rows_customers';

$num_rows_customers = 10;

echo "

{$$displayCode}

";

演示 About Variable variables read here $displayCode = 'num_rows_customers';

$num_rows_c

...

概述代码中的错误,并提供经过测试的工作解决方案: 你正在调用prepare()函数两次。 为SELECT使用错误的变量。 ...使用$sql ,它应该是$stmt 不可能调用你的getManger()函数。 使用连字符而不是等号$age - $row['age']; => $age = $row['age']; 改写: <?php

$db_host = "localhost";

$db_username = "root";

$db_pass = "";

$db_name = "testdb";

...

您可以在PHP和HTML代码之间自由切换。 有时,对于控制流语句而不是大括号,使用备用冒号和结尾语法会有所帮助。 <?php if ($username && $moderator == 1): ?>

You can edit this.

...

...

if ($numrows > 0):

?>

} else {

echo "something in here";

}

显而易见的替代方案是否定: <?php

if (!empty($page['data'])) {

echo "something in here";

}

You can "echo" an empty string, you formally can eve

...

是的,它告诉函数停止执行,并返回值“false”。 所以它做了一些事情。 是否有用取决于您的编程。 如果在echo之后没有可执行行,并且该函数不需要返回值,那么它实际上不会做任何有用的事情。 如果确实让读者更清楚“这是一个停止/失败点”。 有一天你可能想要实际陷阱,如果它工作或失败 - 所以留下它使它更清楚。 您也可以在不考虑的情况下扩展功能,并且需要重新调整返回值 - 再次,将其放入使其更容易。 相反,还有来自C / Assembler日期的旧编程风格,你只有一个入口和一个出口点,所有函数都可以

...

过度使用echo语句会减慢最终用户加载时间吗? 没有。 通过在文件中包含更多的echo语句,文件大小会增加,所以我知道这将是一个因素。 如我错了请纠正我。 你错了。 这是否意味着PHP实际上花了更少的时间来执行,反过来加快了最终用户端的速度? 没有。 或者真的没有任何区别吗? 是。 也许我正在谈论这个或者看错了? 当然。 与性能相关的问题存在共同的问题。 他们中的大多数人不是出于真正的需要,而是出于想象。 虽然人们必须解决实际问题,而不是可以想象的问题。 Does the overly use o

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值