Script to copy / paste an RSS feed file from a remote location to my server

I want to run cronjob from my server, which pulls the rss file from a remote location and copies it to my server. So the rss feed file on my server will be updated as on the remote.

But the crown is simple. I cannot create / run a cronjob from a command, instead I can schedule a cronjob for my domain by selecting the time / day and the file that will be used for this cronjob so that it runs the file at the scheduled time. The PHP code in this file does the rest. But I don’t know how to make the script pull the rss feed from the remote URL to my server with this. You have an idea / script for this.

I want to say that I want to copy and paste a new copy of the rss feed file from a remote server to the location of my server, replacing the old file, if there is one, and this process continues in my schedule

I can not pull out the content elements from the rss channel, instead I want the file to copy / paste

+3
source share
1 answer

If you have a remote wrapper url fopen(), this is pretty simple.

Your PHP cron file will look something like this:

<?php

// If you are running via CLI, deny all non CLI requests
if (PHP_SAPI !== 'cli') {
    exit;
}

$remoteFeed = 'http://example.com/feed.rss';

$feed = file_get_contents($remoteFeed);

if ($feed !== FALSE) {  

    file_put_contents('feed.rss', $feed);

}

Your file feed.rssmust be a copy of the deleted file. If an error occurred while retrieving the deleted file, your local copy will not be updated. If the remote server responds with an empty response body, it will be updated.

allow_fopen_url on, cURL.

+2

Source: https://habr.com/ru/post/1780363/


All Articles