首页 \ 问答 \ 避免重复php include / require(avoid duplication of php include/require)

避免重复php include / require(avoid duplication of php include/require)

我一直想知道这一点,我还没有看到SE中的答案。

当在php中使用包含时,我的工作理解是包含的任何代码都将由服务器处理。

这意味着在下面的条件中,两个大的代码块都在服务器上处理,即使这些代码中只有一个将是EMPLOYED。

<?php
if($conditional === TRUE){
    include("MASSIVEAMOUNTOFCODE.php");
}
else {
    include("GARGANTUANAMOUNTOFCODE.php");
}
?>

(请在此赦免严重简化的代码。)

我最近开始使用以下结构来执行相同的任务,目的是节省服务器上的处理时间。 请告诉我,如果只加载一个包含文件,或者我是在傻瓜的差事:

<?php
if($conditional === TRUE){
    $includeFile = "MASSIVEAMOUNTOFCODE.php";
}
else {
    $includeFile = "GARGANTUANAMOUNTOFCODE.php";
}

include("$includeFile");
?>

注意第一个样本中“include”的双重用法,第二个样本中只使用“include”。


I have been wondering this for a while, and I have not yet seen the answer in SE.

When using includes in php, my working understanding is that any code that is included will be processed by the server.

This would mean that in the following conditional, both large blocks of code are PROCESSED on the server even though only one of these includes will be EMPLOYED.

<?php
if($conditional === TRUE){
    include("MASSIVEAMOUNTOFCODE.php");
}
else {
    include("GARGANTUANAMOUNTOFCODE.php");
}
?>

(Please pardon the grossly simplified code here.)

I have recently started using the following structure to perform the same task, with the aim of saving processing time on the server. Please tell me if this loads only a single include file, or if I am on a fool's errand:

<?php
if($conditional === TRUE){
    $includeFile = "MASSIVEAMOUNTOFCODE.php";
}
else {
    $includeFile = "GARGANTUANAMOUNTOFCODE.php";
}

include("$includeFile");
?>

Note the double usage of "include" in the first sample, and only a single use of "include" in the second sample.


原文:https://stackoverflow.com/questions/39624656
更新时间:2020-01-31 20:26

最满意答案

我不知道你使用的是哪个版本的jsoup ,但是根据最新版本,只有url的解析方法不可用。 你需要通过一次超时。 所以试试吧

Document doc = Jsoup.parse(url, 30000);

有一个连接方法是最好的选择(IMO)。 你可以直接传递stringURL变量。 尝试

Document doc = Jsoup.connect(strURL).get();

如果这些没有帮助检查艺术家和歌曲变量的价值。


I dont know which version of jsoup your are using, but as per latest version the parse method with url alone is not available. You need to pass a timeOut. So try

Document doc = Jsoup.parse(url, 30000);

There is a connect method which would be the best option (IMO). You could pass the stringURL variable directly. Try

Document doc = Jsoup.connect(strURL).get();

If these didn't help check the value of artist and song variables.

相关问答

更多