Jump to content

Archived

This topic is now archived and is closed to further replies.

salvador2001

script works but ..

Recommended Posts

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:

[code]<?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>";

;
?>
[/code]

Share this post


Link to post
Share on other sites
You could try suppressing the error, might be the best solution here. eg;

[code=php:0]
$status = @socket_get_status($s_con);
[/code]

Share this post


Link to post
Share on other sites
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.";
}

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
"//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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.