Minequery tutorial help

Post here is you are having problems with any of the tutorials.
Post Reply
robinatorzzz
Posts: 8
Joined: Mon Jul 18, 2011 10:15 pm

Minequery tutorial help

Post by robinatorzzz »

Hye so i get a bunch of errors, first of all, here is my code:

Index.php
<?php 	
include ('core/init.inc.php');

$info = fetch_server_info($config['server']['ip'], $config['server']['port']);

?>
<html>
<head>
	<title><?php echo $config['server']['ip']; ?> Status</title>
</head>
<body>
	<div>
		<h1><?php echo $config['server']['ip']; ?></h1>
		
		<?php 
		if ($info === false){
			?>
			<p>
				Status: Offline
			</p>
			<?php 
		}else{
			?>
			<p>
				Status: Online
			</p>
			<p>
				Slots: <?php echo $info['playerCount'];?> / <?php echo $info['maxPlayers'];?>
			</p>
			<p>
				Players: <?php echo implode('', $info['playerList']);?>
			</p>
			<?php 
		}
		?>
	</div>
</body>
</html>
core/config.inc.php
<?php
$config['server']['ip']   = 'robinatorzzzz.zapto.org';
$config['server']['port'] = '25565';
?>
core/init.inc.php
<?php
$path = dirname(__FILE__);

include ("{$path}/config.inc.php");
include ("{$path}/inc/mc.inc.php");
?>
core/inc/mc.inc.php
<?php

// fetches server information from minequery.
function fetch_server_info($ip, $port){
	$socket = fsockopen($ip, $port, $errno, $errstr, 0.5);
	
	if($socket === false){
		return false;
	}
	
	fwrite($socket, "QUERY_JSON\n");
	
	$response = stream_get_contents($socket);
	
	return json_decode($response, true);
}
?>
The errors i get...

Erro NR 1 (When the server is offline)

Warning: fsockopen() [function.fsockopen]: unable to connect to robinatorzzzz.zapto.org:25565 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\xampp\htdocs\workspace\minecraft server - minequery\core\inc\mc.inc.php on line 5

Output:
robinatorzzzz.zapto.org

Status: Offline


Erro NR 2 (When the server is online)

Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\workspace\minecraft server - minequery\index.php on line 31

Output:
robinatorzzzz.zapto.org

Status: Online

Slots: /

Players:





Thnx in advance!!
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minequery tutorial help

Post by jacek »

Ah okay, I should have mentioned this in the video, when the server is offline the connection does fail so this error is normal. It's explain a bit more in the other minecraft video on the server status page. The fix is to put a @ before the fsockopen line.
robinatorzzz wrote:Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\workspace\minecraft server - minequery\index.php on line 31
Can you add a print_r($info) before the implode line ? I have never seen this erorr before, it would normally say why they are invalid. Are you sure you are using a recent version of php ?
Image
robinatorzzz
Posts: 8
Joined: Mon Jul 18, 2011 10:15 pm

Re: Minequery tutorial help

Post by robinatorzzz »

Print_r doesn't do anything, this is my php version


PHP Version 5.3.5
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minequery tutorial help

Post by jacek »

robinatorzzz wrote:Print_r doesn't do anything, this is my php version
it should have done, can you post the code you are using with the print_r ?

also make sure you have error_reporting set to E_ALL as that will show up any variable name typos that would otherwise be hard to spot.
Image
Pel02
Posts: 5
Joined: Sat Sep 24, 2011 7:08 pm

Re: Minequery tutorial help

Post by Pel02 »

Hello, I really liked your video tutorials!
I have a similar problem, but I have no any error. Connection to the server is successful, but info array is empty.
error_reporting was set to E_ALL
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minequery tutorial help

Post by jacek »

Try outputting the response form the server directly, the format may have changed.
Image
Pel02
Posts: 5
Joined: Sat Sep 24, 2011 7:08 pm

Re: Minequery tutorial help

Post by Pel02 »

Sorry. How?:)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minequery tutorial help

Post by jacek »

Pel02 wrote:Sorry. How?:)
Add an echo...
echo $responce;
:D
Image
Pel02
Posts: 5
Joined: Sat Sep 24, 2011 7:08 pm

Re: Minequery tutorial help

Post by Pel02 »

This does not work. '$responce' is empty. :(
robinatorzzz
Posts: 8
Joined: Mon Jul 18, 2011 10:15 pm

Re: Minequery tutorial help

Post by robinatorzzz »

maybe it is $response instead of $responce...
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minequery tutorial help

Post by jacek »

Pel02 wrote:This does not work. '$responce' is empty. :(
robinatorzzz wrote:maybe it is $response instead of $responce...
^^ Make sure you have the variable name right. If it is right, try var_dump($responce);
Image
Pel02
Posts: 5
Joined: Sat Sep 24, 2011 7:08 pm

Re: Minequery tutorial help

Post by Pel02 »

var_dump($responce) = NULL ;(
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minequery tutorial help

Post by jacek »

Pel02 wrote:var_dump($responce) = NULL ;(
I think we are alternating between response and responce, you should var_dump() that variable that you assigned the result of the stream_get_contents() function to.
Image
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: Minequery tutorial help

Post by Helx »

Change the port in config.inc.php from 25565 to 25566, this is the default MineQuery port :)
$config['server']['port'] = '25566';
Post Reply