Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3fb561f

Browse files
committedMar 2, 2013
Fix #15558: url_get() fallback to next method in case of error
1 parent d9037aa commit 3fb561f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed
 

‎core/url_api.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,38 @@
2626

2727
/**
2828
* Retrieve the contents of a remote URL.
29-
* First tries using built-in PHP modules, then
30-
* attempts system calls as last resort.
29+
* First tries using built-in PHP modules (OpenSSL and cURL), then attempts
30+
* system call as last resort.
3131
* @param string URL
32-
* @return string URL contents
32+
* @return null|string URL contents (NULL in case of errors)
3333
*/
3434
function url_get( $p_url ) {
3535

3636
# Generic PHP call
3737
if( ini_get_bool( 'allow_url_fopen' ) ) {
38-
return @file_get_contents( $p_url );
38+
$t_data = @file_get_contents( $p_url );
39+
40+
if( $t_data !== false ) {
41+
return $t_data;
42+
}
43+
# If the call failed (e.g. due to lack of https wrapper)
44+
# we fall through to attempt retrieving URL with another method
3945
}
4046

4147
# Use the PHP cURL extension
4248
if( function_exists( 'curl_init' ) ) {
4349
$t_curl = curl_init( $p_url );
4450
curl_setopt( $t_curl, CURLOPT_RETURNTRANSFER, true );
51+
# @todo It may be useful to provide users a way to define additional
52+
# custom options for curl module, e.g. proxy settings and authentication.
53+
# This could be stored in a global config option.
4554

4655
$t_data = curl_exec( $t_curl );
4756
curl_close( $t_curl );
4857

49-
return $t_data;
58+
if( $t_data !== false ) {
59+
return $t_data;
60+
}
5061
}
5162

5263
# Last resort system call

0 commit comments

Comments
 (0)
Please sign in to comment.