繁体   English   中英

PHP脚本,用于从特定URL加载和缓存XML数据库的副本

[英]PHP script to Load and Cache a copy of XML database from specific URL

我有一个数据库,该数据库会延迟很多时间以xml格式加载,假设URL为www.mysite.com/my-database/,我需要一个PHP脚本来加载此URL并在加载后保存内容的副本(加载数据库所需的时间超过120秒),并将其副本存储在我网站的根目录中,名称为db.xml。 感谢帮助。

Iam发送答案

基本上,您要做的就是将页面信息存储在一个变量中,然后设置位置并将变量作为要保存到您设置的位置的信息,因此:

file_put_contents('/完整服务器路径/到/要保存的文件/file.ext',$the_variable_you_set_with_the_page_info);

如果您不知道如何在创建文件的脚本中将页面信息存储在变量中,则可以使用PHP创建一个简单的打开/保存文件。

<?php

# This will open the actual xml page on your site with
# PHP and store the info in a variable. [Obviously you
# Have to change the location to the URL of the actual
# XML page people view.]

$the_variable_you_set_with_the_page_info=file_get_contents('http://www.yoursite.com/your-xml-file-to-save.xml');

 # Then you can save the file info where ever you would like.
 # For this one you'll have to find your server path which is
 # usually something like /home/public_html/the-directory-to-use

file_put_contents('/the-full-server-path/to-where/you-want-the-file-saved/file.ext',$the_variable_you_set_with_the_page_info);

 ?> 

暂无
暂无

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

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