|
26 | 26 |
|
27 | 27 | /**
|
28 | 28 | * 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. |
31 | 31 | * @param string URL
|
32 |
| - * @return string URL contents |
| 32 | + * @return null|string URL contents (NULL in case of errors) |
33 | 33 | */
|
34 | 34 | function url_get( $p_url ) {
|
35 | 35 |
|
36 | 36 | # Generic PHP call
|
37 | 37 | 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 |
39 | 45 | }
|
40 | 46 |
|
41 | 47 | # Use the PHP cURL extension
|
42 | 48 | if( function_exists( 'curl_init' ) ) {
|
43 | 49 | $t_curl = curl_init( $p_url );
|
44 | 50 | 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. |
45 | 54 |
|
46 | 55 | $t_data = curl_exec( $t_curl );
|
47 | 56 | curl_close( $t_curl );
|
48 | 57 |
|
49 |
| - return $t_data; |
| 58 | + if( $t_data !== false ) { |
| 59 | + return $t_data; |
| 60 | + } |
50 | 61 | }
|
51 | 62 |
|
52 | 63 | # Last resort system call
|
|
0 commit comments