I would like to schedule a task for accessing a fresh xml file once in a day from a website and replace (or update the old xml file) residing on my computer. The old xml file is saved on my localhost as an archived copy.
How can I schedule this task automatically and make php automatically access the new file from a website and update my xml file once a day.
Wamp is on windows right, so I think you might have to use windows scheduling or some other software like that to have it call your script in certain time intervals.
I don’t know what windows version you have but here is microsoft tutorial on scheduler for XP
thanks for the reply. I can create a task on my windows 7 but how would I configure the php script that will read the fresh xml file and (update or replace) the one on my computer.
Well that is a little bit more complex task. But basically I would look into some tutorials on reading/writing files in php , also check out file_get_contents() , that will let your read a file into variable in php.
I can now read the xml file from a web link using file_get_contents() from my php code.
And it displays exactly what I need. No problems.
Now I can use this weblink to get the updated xml data only once in a day. I need to put this php script in a windows scheduler.
Please reply. How i can do it.
The code that I use to access the xml from a website is:
//this is the link I access once in a day
$xml_file = "http://mydomain.com/TheUpdatedxmlFile.xml";
$xmlstr = file_get_contents($xml_file);
if (!empty($xmlstr) && !empty($SetCurrency))
{
$xml = new SimpleXMLElement($xmlstr);
$currencies = array();
foreach ($xml->currency AS $a_currency) {
$csymbol = $a_currency->csymbol;
$crate = $a_currency->crate;
$currencies["$csymbol"] = $crate;
}
$c_rate = $currencies[AUD];
}
Please reply I need to convert this into some script and put this in the windows scheduler.
Thanks cranial-bore, could you please share some sample code on how to run this program nn_cron.
I am accessing the updated xml file via the link as:
//this is the link I access once in a day
$xml_file = "http://mydomain.com/TheUpdatedxmlFile.xml";
$xmlstr = file_get_contents($xml_file);
if (!empty($xmlstr) && !empty($SetCurrency))
{
$xml = new SimpleXMLElement($xmlstr);
$currencies = array();
foreach ($xml->currency AS $a_currency) {
$csymbol = $a_currency->csymbol;
$crate = $a_currency->crate;
$currencies["$csymbol"] = $crate;
}
$c_rate = $currencies[EUR];
}
Now this code will run everytime the page is loaded. I need to convert this into some script and perhaps use it through the program u suggested ‘nn_cron’ once in a day and update the one on my local machine.
So basically I just need a code that will replace (or update) the old xml on my localhost with the fresh xml file through a link i.e.
http://mydomain.com/TheUpdatedxmlFile.xml
And then once I have the xml file on my localhost updated, I will simply read from the localhost using the code I pasted above.
So I just need a script that will update the old xml file with the new xml file through some scheduler. You suggested nn_cron, so whats the best way to do we do update files thru nn_cron.
So the line in the cron.tab to execute a PHP script on your computer at 2:15pm, 3:15pm and 4:15pm every Tuesday would look like this:
15 14-16 * * 2 php -q c:\\path\ o\\myphpfile.php
Your PHP file may need to use absolute paths, as it will be executing relative to where PHP is installed.
It’s like executing PHP via the command line on a schedule.