简体   繁体   English

获取大量信息时如何使 php 页面加载速度更快?

[英]How to make php pages load faster when fetching bulk of information?

Basically I am building a website that does web scraping and fetches particular web pages from around 8 different websites to extract price.基本上我正在建立一个网站,该网站进行网络抓取并从大约 8 个不同的网站获取特定网页以提取价格。 I am using file_get_html() function of PHP Simple HTML DOM Parser extensively to fetch the page source into a string variable and extract the price information out of that.我广泛使用PHP Simple HTML DOM Parserfile_get_html()函数将页面源提取到字符串变量中,并从中提取价格信息。

Now the main problem is the page which shows the price information from all different sites is taking very long time to load.现在的主要问题是显示来自所有不同站点的价格信息的页面需要很长时间才能加载。

So my question is所以我的问题是

  1. How to make the page load faster.如何使页面加载速度更快。 & &
  2. How to load the page in steps so that those information which has been fetched loads and other information will load subsequently like google image search.如何分步加载页面,以便加载那些已获取的信息和其他信息将随后加载,如谷歌图片搜索。

Don't fetch the data on page load, but do it in a background job (cronjob?) and save it in the database.不要在页面加载时获取数据,而是在后台作业(cronjob?)中获取数据并将其保存在数据库中。

So you will only have to retrieve the data from the database.所以你只需要从数据库中检索数据。 Additionally you could add a text with a timestamp when the data has been retrieved and / or give the user the ability to manually update (get) the data.此外,您可以在检索到数据时添加带有时间戳的文本和/或让用户能够手动更新(获取)数据。

Well, first of you can use cURL instead of file_get_html() , It's easy and very configurable + it's faster than using the simple html dom function.好吧,首先你可以使用 cURL 而不是file_get_html() ,它很容易并且非常可配置 + 它比使用简单的 html dom 函数更快。 Obviously you will have to convert the string into a dom object using the simple html dom function str_get_html() after that.显然,之后您必须使用简单的 html dom 函数str_get_html()将字符串转换为 dom 对象。

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

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