Piwik\Http::fetchRemoteFile PHP Method

fetchRemoteFile() public static method

Fetches a file located at $url and saves it to $destinationPath.
public static fetchRemoteFile ( string $url, string $destinationPath = null, integer $tries, integer $timeout = 10 ) : boolean
$url string The URL of the file to download.
$destinationPath string The path to download the file to.
$tries integer (deprecated)
$timeout integer The amount of seconds to wait before aborting the HTTP request.
return boolean `true` on success, throws Exception on failure
    public static function fetchRemoteFile($url, $destinationPath = null, $tries = 0, $timeout = 10)
    {
        @ignore_user_abort(true);
        SettingsServer::setMaxExecutionTime(0);
        return self::sendHttpRequest($url, $timeout, 'Update', $destinationPath);
    }

Usage Example

Exemplo n.º 1
0
 public function get()
 {
     try {
         $content = Http::fetchRemoteFile($this->url);
         $rss = simplexml_load_string($content);
     } catch (\Exception $e) {
         echo "Error while importing feed: {$e->getMessage()}\n";
         exit;
     }
     $output = '<div style="padding:10px 15px;"><ul class="rss">';
     $i = 0;
     $items = array();
     if (!empty($rss->channel->item)) {
         $items = $rss->channel->item;
     }
     foreach ($items as $post) {
         $title = $post->title;
         $date = @strftime("%B %e, %Y", strtotime($post->pubDate));
         $link = $post->link;
         $output .= '<li><a class="rss-title" title="" target="_blank" href="?module=Proxy&action=redirect&url=' . $link . '">' . $title . '</a>' . '<span class="rss-date">' . $date . '</span>';
         if ($this->showDescription) {
             $output .= '<div class="rss-description">' . $post->description . '</div>';
         }
         if ($this->showContent) {
             $output .= '<div class="rss-content">' . $post->content . '</div>';
         }
         $output .= '</li>';
         if (++$i == $this->count) {
             break;
         }
     }
     $output .= '</ul></div>';
     return $output;
 }
All Usage Examples Of Piwik\Http::fetchRemoteFile