Reading an xml file every minute

Hi all,

My php script is doing:
  $doc->load( 'myfile.xml' );
And I need it to do so every single minute as the xml values change quite frequently and the php has to be updated with them ..

How can I do that?

Thanks a ton in advance!
Dada44Asked:
Who is Participating?
 
xSuperioRxConnect With a Mentor Commented:
Hello

Hopefully this snippet will help you, i use this myself to rotate images.

Lets say you have all that in a div ( in my case id="leftbottom" for it)

That snippet runs /scripts/rotateimage.php with the specified interval (my case 15000).

Each time its run the rotateimage.php is also run and the contents of rotateimage.php goes into the leftbottom div.

So one way i guess you could use it is to include that file in your version of "rotateimage.php" then it should load every interval and display in the selected div, smoothly :)

Please not, i'm not a expert on ajax. There can be better solutions for you as well, just thought i'd share the one i use :)
function getHTTPObject() {
 
 var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
				try {
				request = new XMLHttpRequest();
				}
				catch (err1) 
				{
				request = false;
				}
            }
        }
    return request;
 
}
 
var ajaxRequest = getHTTPObject(); // We create the HTTP Object
 
setInterval(getPictures, 15000); 
function getPictures() {
 
		var queryString = "?lang=eng";
		ajaxRequest.open("GET", "/scripts/rotateimage.php" + queryString, true);
		ajaxRequest.onreadystatechange = showPictures;
		ajaxRequest.send(null); 
		
}
			
function showPictures()
{
		if(ajaxRequest.readyState == 4){
				var ajaxDisplay = document.getElementById('leftbottom');
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
				
			}						
}
window.onload=function(){
	getPictures(); 
}

Open in new window

0
 
Michael701Commented:
most common way would be to setup a cron job.

if you don't have server rights for that. I was thinking maybe adding this to the end of  your code

sleep(60);
header ("location: ".$_SERVER['PHP_SELF'] );
0
 
xSuperioRxCommented:
<meta http-equiv="refresh" content="60;url=yourpage.php" />

That might do what you want aswell.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Dada44Author Commented:
that could be a solution .. I'm adding it at the bottom of the page, right before ?> but it keeps loading and nothing shows ..
Thanks for answering!
0
 
Dada44Author Commented:
xSuperioRx: thanks, but it shows how the page is reloaded and I was looking for a smooth way to do it.
That's why I was trying to get the xml file reloaded into the php and not the php itself ..
Thanks also for answering
0
 
Michael701Connect With a Mentor Commented:
Ah, so this is displayed on a browser page. Forget my first solution, it was for no output updating a database.

You'll probably need to use ajax. This way you can get the new data and update a portion of the page without any page refreshes.
0
 
xSuperioRxCommented:
Yes you will need to use ajax to not show the page reloading. Smoothest way with ajax. Did some digging and this should help you on the way.

http://www.dayrecipe.com/2008/04/01/php-ajax-auto-refresh-div/

If thats confusing for you, you should google "auto refresh ajax" or something for more clues how to fix your problem :)
0
 
Dada44Author Commented:
Sounds great, but pardon my dumbness .. if I'm doing:
<?
$doc = new DOMDocument();
  $doc->load( 'myfile.xml' );
 
  $books = $doc->getElementsByTagName( "book" );
  foreach( $books as $book )
 {
  $aa = $book->getElementsByTagName( "authorr" );
  $a = $aa->item(0)->nodeValue;
.
.
.

and what I need to refresh all the time is the   $doc->load( 'myfile.xml' );
where do I insert ajax in there ?

Thanks a ton to both!
0
 
Dada44Author Commented:
Thanks!!!!!!!!!!!!!!!!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.