function taxonomy_xml_cached_get_contents in Taxonomy import/export via XML 6
Same name and namespace in other branches
- 6.2 taxonomy_xml.module \taxonomy_xml_cached_get_contents()
- 7 taxonomy_xml.module \taxonomy_xml_cached_get_contents()
A caching version of file_get_contents. Used to try and minimize remote URL lookups.
2 calls to taxonomy_xml_cached_get_contents()
- taxonomy_xml_import_form_submit in ./
taxonomy_xml.module - Imports the actual XML.
- taxonomy_xml_import_from_url in ./
taxonomy_xml.module - Import one URL. Function used by the batch operation
File
- ./
taxonomy_xml.module, line 1067 - taxonomy_xml.module This module makes it possible to import and export taxonomies as XML documents.
Code
function taxonomy_xml_cached_get_contents($url, $flush = FALSE) {
// Note this current active URL for reference in debuging in distant places
global $_taxonomy_xml_current_doc;
$_taxonomy_xml_current_doc = $url;
$cachedir = file_directory_path() . '/url_cache';
$save_as = $cachedir . '/' . md5($url);
if (file_exists($save_as)) {
$content = file_get_contents($save_as);
if ($content) {
// Occasionally got zero-length reponses?
return $content;
}
}
// else
file_check_directory($cachedir, FILE_CREATE_DIRECTORY);
$contents = file_get_contents($url);
file_put_contents($save_as, $contents);
return $contents;
}