Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #15558: url_get() fallback to next method in case of error

  • Loading branch information...
commit 910546df61398e49a12113869db7f993c21f7ca1 1 parent 352c4bf
@dregad dregad authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 core/url_api.php
View
21 core/url_api.php
@@ -28,27 +28,38 @@
/**
* Retrieve the contents of a remote URL.
- * First tries using built-in PHP modules, then
- * attempts system calls as last resort.
+ * First tries using built-in PHP modules (OpenSSL and cURL), then attempts
+ * system call as last resort.
* @param string URL
- * @return string URL contents
+ * @return null|string URL contents (NULL in case of errors)
*/
function url_get( $p_url ) {
# Generic PHP call
if( ini_get_bool( 'allow_url_fopen' ) ) {
- return @file_get_contents( $p_url );
+ $t_data = @file_get_contents( $p_url );
+
+ if( $t_data !== false ) {
+ return $t_data;
+ }
+ # If the call failed (e.g. due to lack of https wrapper)
+ # we fall through to attempt retrieving URL with another method
}
# Use the PHP cURL extension
if( function_exists( 'curl_init' ) ) {
$t_curl = curl_init( $p_url );
curl_setopt( $t_curl, CURLOPT_RETURNTRANSFER, true );
+ # @todo It may be useful to provide users a way to define additional
+ # custom options for curl module, e.g. proxy settings and authentication.
+ # This could be stored in a global config option.
$t_data = curl_exec( $t_curl );
curl_close( $t_curl );
- return $t_data;
+ if( $t_data !== false ) {
+ return $t_data;
+ }
}
# Last resort system call
Please sign in to comment.
Something went wrong with that request. Please try again.