Jump to content
php.lv forumi

udp portu čekošana


Recommended Posts

Labdien!

Man lūk ir šāds skripts:

 

<?php
$ip = "127.0.0.1";
$ports = "27051";
$socket = fsockopen("udp://".$ip, $ports);
$cmd = "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00";
$lenght = strlen($cmd);
fwrite($socket, $cmd, $lenght);
$response = fread($socket, 1);

if (!empty($response))
{
   echo "<center><p style=\"font-size: 12px Tahoma; font-weight: bold; color: #00FF00;\">Online</p></center>";
} else
{
   echo "<center><p style=\"font-size: 12px Tahoma; font-weight: bold; color: #ff4400;\">Offline</p></center>";
}
?>

 

Viņš pārbauda, vai norādītais ports eksistē.

Problēma tāda, ja ports neeksistē jeb process ir offline, tad viņš ļoti ilgi viņu lādē, apmēram minūti.

Kad ports eksistē jeb process ir online, tad viņš monemtāli viņu pārbauda.

Ko skriptam vajadzētu samainīt, lai viņš momentāli arī pārbaudītu, kad process ir offline?

Edited by Janka no Benzin Tanka
Link to comment
Share on other sites

Skripts tagad izkatās šadi:

<?php
$ip = "127.0.0.1";
$ports = "27052";
$socket = fsockopen("udp://".$ip, $ports, $errno, $errstr, 1);
$cmd = "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00";
$lenght = strlen($cmd);
fwrite($socket, $cmd, $lenght);
$response = fread($socket, 1);

if (!empty($response))
{
   echo "<center><p style=\"font-size: 12px Tahoma; font-weight: bold; color: #00FF00;\">Online</p></center>";
} else
{
   echo "<center><p style=\"font-size: 12px Tahoma; font-weight: bold; color: #ff4400;\">Offline</p></center>";
}
?>

 

Bet tāpat ilgi lādē.

Varētu būt vaina FW? Jo k-kad sen, šis pirmais skripts strādāja perfekti.

Tagad cits FW, un nestrādā tā kā vajag.

Edited by Janka no Benzin Tanka
Link to comment
Share on other sites

monitorēt serveri taisies? ^^

stream_set_timeout($socket, 0, 800 * 1000); liec šo pēc fsockopen rindiņas ^^ tikai neuzliec par maz laiku.. kad tālāk liksi kvērijus, tad var arī attrūkties laika, lai iegūtu datus..

Edited by ezis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...