Jump to content


Photo

script works but ..


  • Please log in to reply
6 replies to this topic

#1 salvador2001

salvador2001
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 24 October 2006 - 05:00 PM

Hello,

I have a problem wich i cant solve because my knowledge of PHP is to little at this moment. So i hope someone can help me out with a problem and give me a clear solution.

This script is working fine when the hosting pc is turned on. The script will clearly show if the game is running or not. But when the hosting pc is turned of i get a error on line 11 wich says:

Fatal error: maximum execution time of 30 seconds.... on line 11.

Can somebody help me with this ?

Here is the script:

<?php

$s_port = 12203;          // Serverport
$s_ip   = "82.217.212.106";    // Server-IP
$s_con = fsockopen("udp://".$s_ip, $s_port);
fwrite($s_con, "ÿÿÿÿ". chr (0x02). "getstatus". chr (0x00));

// testen verbindings opbouw

fread($s_con, 4);
$status = socket_get_status($s_con);

// SERVER DOWN

if($status["unread_bytes"] == 0) 
{
 echo "<div align='left'>
  <table width='20%' border='1' cellpadding='0' cellspacing='0' bordercolor='#465461'>
    <tr> 
      <td colspan='3'> <div align='center'><strong>Hier Plaatje</strong></div></td>
    </tr>
   <tr> 
      <td colspan='3'> <div align='center'><strong>server
          status</strong></div></td>
    </tr>   
    <tr bordercolor='#2D3740'>
      <td align='center'><strong>Server down</strong></td>";
 die();
}

$beginnen = "";

do
{
 $beginnen .= fread($s_con, 1);
 $status = socket_get_status($s_con);
}
while($status["unread_bytes"] != 0);

fclose($s_con);

$data = explode("\n", $beginnen);


// Serverinformatie

$s_con = fsockopen("udp://".$s_ip, $s_port);
fwrite($s_con, "ÿÿÿÿ". chr (0x02). "getstatus". chr (0x00));

// bytes lezen en verbindingsopbouw

fread($s_con, 4);
$status = socket_get_status($s_con);

if($status["unread_bytes"] == 0) 
{
 echo "no info. sorry";
 die();
}

$beginnen = "";

do
{
 $beginnen .= fread($s_con, 1);
 $status = socket_get_status($s_con);
}
while($status["unread_bytes"] != 0);

fclose($s_con);


echo"
<div align='left'>
  <table width='20%' border='1' cellpadding='0' cellspacing='0' bordercolor='#465461'>
    <tr> 
      <td colspan='3'> <div align='center'><strong>hier plaatje</strong></div></td>
    </tr>
   <tr> 
      <td colspan='3'> <div align='center'><strong>server
          status</strong></div></td>
    </tr>   
    <tr bordercolor='#2D3740'>
      <td align='center'><strong>Playing Mohaa or Spearhead</strong></td>";
	
;
?>


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 24 October 2006 - 06:21 PM

You could try suppressing the error, might be the best solution here. eg;

$status = @socket_get_status($s_con);


#3 Psycho

Psycho
  • Moderators
  • Move along, nothing to see here
  • 11,891 posts
  • LocationCanada

Posted 24 October 2006 - 06:27 PM

Of you could put in a conditional to display a message if the server is down:

if ($status = socket_get_status($s_con)) {
  //Insert normal code from above
} else {
  echo "Server is down.";
}
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#4 salvador2001

salvador2001
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 24 October 2006 - 06:57 PM

I dont understand //insert normal code from above, i tried a few things but like i said, my knowledge is poor.

if ($status = socket_get_status($s_con)) {
fread($s_con, 4);
$status = socket_get_status($s_con);
} else {
  echo "Server is down.";
}

I am sure its wrong because the script doesnt work like it should. Can you be more specific please sir ?

#5 salvador2001

salvador2001
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 31 October 2006 - 09:24 PM

can anybody help me please ?

#6 Psycho

Psycho
  • Moderators
  • Move along, nothing to see here
  • 11,891 posts
  • LocationCanada

Posted 01 November 2006 - 05:15 AM

"//Insert normal code from above" is a comment

I meant you should include the code you had previously to do whatever process you want to accomplish.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#7 salvador2001

salvador2001
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 02 November 2006 - 07:43 PM

Problem solved.

Thank you very much !




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users