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