简体   繁体   English

减少PHP服务器请求

[英]Reduce php server requests

Probably a very stupid question, but I'm wondering how php works. 可能是一个非常愚蠢的问题,但是我想知道php是如何工作的。 I'm trying to find ways to improve the php of my WordPress themes. 我正在尝试寻找改善WordPress主题的php的方法。

<?php
echo "PHP script.";
?>
<?php
echo "More PHP script!";
?>

Will I reduce the number of requests/processes if I put them together like this 如果将这样的请求/流程放在一起,我会减少请求/流程的数量吗?

<?php
echo "PHP script. More PHP script!";
?>

What I actually want to know is will there be a request to the server every time there is a < ?php and can I or do I reduce the number of requests by combining them? 我真正想知道的是,每当有一个<?php时,服务器都会有一个请求,我是否可以合并这些请求来减少请求的数量?

I'm not sure you understand what a "request" is in this context, and you may be mixing terminology (which is leading to your confusion on the matter). 我不确定您是否理解这种情况下的“请求”,并且您可能在混用术语(这导致您对此事感到困惑)。

To answer the question... No, having multiple lines of PHP code in a single file does not perform additional HTTP requests. 要回答这个问题...不,在单个文件中包含多行PHP代码不会执行其他HTTP请求。

When you make a request to a URL, such as: 当您请求URL时,例如:

http://www.example.com/somePage.php

That creates one request. 这创建了一个请求。 The server-side code in somePage.php is processed in its entirety and the result of that processing is sent to the client in response to the request. somePage.php的服务器端代码将进行somePage.php处理并根据请求将处理结果发送给客户端。 At this point the request/response is done. 至此,请求/响应完成。

The request has literally nothing to do with how many lines of PHP code are on the page. 该请求实际上与页面上多少行PHP代码无关

I'm trying to find ways to improve the php of my WordPress themes. 我正在尝试寻找改善WordPress主题的php的方法。

Well, in order to do that you first would need to identify something that needs to be improved. 好吧,为了做到这一点,你首先需要找出一些需要加以改进。 Don't just randomly shuffle your code around and hope it makes things better in some immeasurable way. 不要只是随意地乱码,而希望它以某种不可估量的方式使事情变得更好。 Measure something, then improve that something. 测量一些东西,然后改进一些东西。

If your page is loading slowly, find out where/how/why that's happening. 如果您的页面加载缓慢,请找出发生的位置/方式/原因。 Maybe you have some code that's taking a long time to process, maybe you have inefficient SQL queries, maybe you're transferring large images to the browser and the network is slow, maybe something else. 也许您有一些代码需要花费很长时间来处理,也许您的SQL查询效率很低,也许您正在将大图像传输到浏览器并且网络很慢,也许还有其他原因。 Don't guess , measure . 不要测量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM