UrlGet
file_get_contents" with "cURL"Questions answered by this extension
I want to use the built in RecipeCheck or Blocklist recipes.
- how do I do this if "
allow_url_fopen" is disabled by my webhost? - how do I do this in preference to "
file_get_contents" used internally by PmWiki? - I want to write a recipe that uses
simplexml_load_file
Description
This extension provides a function UrlGet which uses cURL to retrieve the contents of the URL.
The global variable $UrlGetFunction is set to UrlGet using the PmWiki function SDV if it is not already set.
The internal PmWiki variable "" is set to "$UrlGetFunctionUrlGet\UrlGet". UrlGet is a function that uses "cURl" to retrieve the contents of a URL.
Returns the URL contents as a string, or FALSE, the same as "file_get_contents".
Returns error messages in .
$FmtV['$UrlGetMsg']
Install as an extension
- download the
urlget-2026-04-16.zipΔarchive - copy the
urlget-2026-04-16.zipΔarchive to the/extension/directory as/urlget/ - uncompress the
urlget-2026-04-16.zipΔarchive (optional, but recommended) - see the Site Admin.Extension Hub to configure the extension
Usage
- enable the extension in the Site Admin.Extension Hub
- check that the built in recipe installation check and BlockList recipes work if used.
Configuration
There is no configuration.
Internationalisations
There are no internationalisations.
Details
Change log / Release notes
2026-04-16: add a test and documentation
2026-04-08: Initial version based on internal code modding diag.php to enable RecipeCheck.
Testing
It has been possible to carry out only limited testing. The extension is in production use on a Windows and a Linux system. A built in test exercises one successful read and one read failure.
- if the extension does not work on Linux from the archive file uncompress it. This is being investigated.
For extension developers
Test if allow_url_fopen is enabled
// check if allow_url_fopen is enabled
$allowUrlFopen = ini_get('allow_url_fopen') === 1;
if (!$allowUrlFopen) {
$retVal .= RECIPENAME . ': "allow_url_fopen" is not enabled.' . BR;
}
To enable use of this extension
SDV($UrlGetFunction, 'file_get_contents'); # defaults to built in function
$fileContents= @$UrlGetFunction($url);
if ($fileContents === FALSE) {
$errMsg = $FmtV['$UrlGetMsg'] ?? '';
$retVal .= RECIPENAME . ': unable to retrieve "' . $url . '" ' . $errMsg . BR;
}
See also
User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.