[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

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!
0
Dada44
Asked:
Dada44
  • 4
  • 3
  • 2
2 Solutions
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
Michael701Commented:
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
 
xSuperioRxCommented:
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
 
Dada44Author Commented:
Thanks!!!!!!!!!!!!!!!!!!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now