简体   繁体   中英

Any way to print contents of a screen to a web page?

I'm running a minecraft server on a screen (screen -X mc java -jar minecraft_server.jar). Is there any way to print the contents of this onto a web page? I was thinking it would be something along the lines of

<?php
$console = exec(console.sh)
echo $console;
header("refresh: 5";);
?>

however this does not print anything. I think it has something to do with the screens being per-user, is there any way to let php run this? Or is there anyway to output the screen to a file and still be able to attach to the screen?

Thanks a ton!

Edit: Answer below works well, however I would suggest http://phpshell.sourceforge.net . You can log into the terminal and display the console along with being able to chat. However this is interactive, and would work only for admins.

Either of these should work.

<?php
$logs = "PATH_TO_SERVER_LOGS/server.log";
$fh = fopen($logs, 'r');
$theData = fread($fh, filesize($logs));
fclose($fh);
echo $theData;
header("refresh: 5");
?>

<?php
//Replace ./server.log with the path to your server logs and make sure apache has the proper //permissions to read the file.
$file = file_get_contents('./server.log', true);
echo $file;
header("refresh: 5");
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM