Skip to content

Commit 910546d

Browse files
committedMar 2, 2013
Fix #15558: url_get() fallback to next method in case of error
1 parent 352c4bf commit 910546d

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
@@ -28,27 +28,38 @@
2828

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

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

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

4857
$t_data = curl_exec( $t_curl );
4958
curl_close( $t_curl );
5059

51-
return $t_data;
60+
if( $t_data !== false ) {
61+
return $t_data;
62+
}
5263
}
5364

5465
# Last resort system call

0 commit comments

Comments
 (0)
Please sign in to comment.