Best way to embed a continuously updating log file into web page?

Hi there everyone!

I’ve got a log file that’s updated continuously via a gameserver and I need to display it to an admin. I’ve played around with iframes but I don’t think that’s the way to handle this particular issue as it’s not working well.

Could someone tell me how I might embed …/…/directory/run.log into index.php? I’m not sure what to even search for, I just know js/ajax/jquery stuff is amazeballs.

In broad terms, you’d need to have PHP continuously read from the log file and stream it to the client. On the client you’d need to use JavaScript to read from the stream and update the page.

In Node, I’d use something like this:

Maybe that gives you an idea of the terms and concepts involved (which might be good for further Googling).

James, thank you so much for your help! I was unable to get that to work on the web server but I did think late last night that I should look at a flatfile chat script that works with an update process. I found one this morning and I’ve gotten it to read the log file. It’s updating as it should but the issue is that the page is not scrolling down to include the new content as it’s added.

Is there anything I can do to this script to get it to always scroll down to show the newest content?

The script in question: http://scotchandiron.org/chat/

Is that link your page, or a link to the script you are using?

I’d have to see how you’re loading the new content, but you could probably add some JS to make sure it scrolled to the new content.

Or, and this would be my preferred solution, have the new content added at the top of the window.

The link is the script I’m using on my domain drawing from my log file.

Is there a way to reverse the display of this script or do I have to change the content of the file it’s drawing from? To be honest, I don’t have a preference but whichever direction it ends up in, I’d like it to show the latest content when it refreshes.

There is a link near the top of the page “toggle: top/bottom display” which does that.

The event handler attached to that link is:

show_newmsg_on_bottom=!show_newmsg_on_bottom

So calling that manually from within your script should do it, or have a look at the source code to see if you can pass in a parameter to do that.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.