Hello, there is an online store in which you need to add products from suppliers. Adding goods through api . Download file in xml format. You need to write a script (preferably in php ) so that this file is automatically updated once a day. That is, the script on the link downloaded the file and placed it on the server or replaced the old file with a new one once a day. How can this be done? Is it possible to do this in JavaScript or is server language needed?
1 answer
For these purposes, it is best to use Cron .
Cron (Command Run ON) is a system for automatically launching programs and scripts on the server at a certain time ( source ).
In a nutshell:
create php file with file upload function
function downloadSrc($file_url, $save_to){ $content = file_get_contents($file_url); file_put_contents($save_to, $content); } downloadSrc('target_xml.xml', realpath("path/to/folder/where/xml_nested") . 'file_name.xml'); Specify this file in the Crone-panel of your host to run, using a special command (for example, hosting ukraine.com.ua , the path to the widget on your host may differ):
/usr/bin/wget -O - -q -t 1 http://your_awesome_site.com/path/to/cron.php Set the frequency of the task (once a day in your case). Now the widget will automatically call the cron.php file and execute the instructions described in it.
The interface on different hosts is different, but the essence is the same. To clarify the details and the nuances communicate with the support of your hosting.
- Thanks, I will try) - Alexey