避免重复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
最满意答案
我不知道你使用的是哪个版本的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.
相关问答
更多-
如果您通过浏览器在服务器上有一些文件,您可以直接读取它。 为此,您可以使用URL类和Scanner 。 当您阅读每一行时,您可以按照自己的意愿解析它。 URL input = new URL("http://files.parsetfss.com/ce686da3-4464-47ec-ba73-24747f2da937/tfss-75cfc482-96ab-45f8-8d8b-80b40a5a0298-http.txt"); Scanner sc = new Scanner(input.openStre ...
-
使用Jsoup进行错误的解析(Incorrect parse with Jsoup)[2022-03-05]
问题解决了这样 Elements epBox = doc.select("div.ep_box h3"); int urlcount = 0; for (Element ep : epBox) { url = ep.select("a").attr("href"); if (urlcount < listItems.size()) { Order o = ... -
JSoup如何解析表3行(JSoup how to parse table 3 rows)[2021-11-17]
试试这样: URL url = new URL("http://www.myurl.com"); Document doc = Jsoup.parse(url, 3000); // This should work now Element tables = doc.select("table tr .id"); // This propably should work too Element tables2 = doc.select("table tr[class*=id]"); for(Element ... -
工作代码: import org.jsoup.Connection; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.io.IOException; import java.util.ArrayList; public class Sample { public static void main(String[] args) { ...
-
您还应该设置一个大的超时,例如: Document = Jsoup.connect(url) .header("Accept-Encoding", "gzip, deflate") .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0") .maxBodySize(0) .timeout(600000) .get(); You should also set a large timeout, ...
-
我不知道你使用的是哪个版本的jsoup ,但是根据最新版本,只有url的解析方法不可用。 你需要通过一次超时。 所以试试吧 Document doc = Jsoup.parse(url, 30000); 有一个连接方法是最好的选择(IMO)。 你可以直接传递stringURL变量。 尝试 Document doc = Jsoup.connect(strURL).get(); 如果这些没有帮助检查艺术家和歌曲变量的价值。 I dont know which version of jsoup your ar ...
-
Jsoup.parse方法试图将发布的HTML代码(或其片段)解析为DOM,但问题是您没有发布HTML而是发布URL。 因为如果结果你得到了包含的DOM https://campus.bk.edu.da/student_trans.asp 如果要从提供的URL获取表示HTML代码的Document,首先需要连接到它。 所以试试吧 Document doc = Jsoup.connect(url).get(); ...
-
它用于Element#absUrl()以便您可以检索 , , ,