[SOLVED] Check to see if a port is open

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

[SOLVED] Check to see if a port is open

Post by Revan »

Hello, im running HLStats, and im making a script that prints weither its up or not

I was thinking some thing like

Code: Select all

$stat_dameon = fsockopen("udp://127.0.0.1","27500");
if ( $stat_dameon ) {
print "Online";
} elseif ( !$stat_dameon ) {
print "Offline";
}
but it doesnt work, any ideas?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Try adding the other parameters to the fsockopen.

Code: Select all

$stat_dameon = fsockopen("127.0.0.1","27500", &$err_num, &$err_msg, 30); 
if ( $stat_dameon ) { 
print "Online"; 
} elseif ( !$stat_dameon ) { 
print "Offline"; 
}
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

thats awesome, you can do that stuff with PHP??

what a great friggin language :)
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

fresh wrote:thats awesome, you can do that stuff with PHP??

what a great friggin language :)
Yes, PHP is the best

first time working with socks

@kettle_drum

that didnt work :/

btw its a UDP port so i tryed doing

Code: Select all

<?php
$stat_dameon2 = fputs($stat_dameon,"test");

?>
but it still says its online
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

Don't think so, absul suck with classes

the problem im having is fsockopen doesnt return that it connected or failed, iit returns a process ID
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

check the warning about 1/4 of the way down http://ca2.php.net/manual/en/function.fsockopen.php . I think you need to actually read something after you've got the pointer using fgets.
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

In the end i used this

Code: Select all

<?php

$socket_hlstats_daemon = @socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
$stat_dameon = @socket_bind($socket_hlstats_daemon , "127.0.0.1", 27500);

if ( $stat_dameon ) {
print "Offline";
} else {
print "Online";
} 
@socket_close($socket_hlstats_daemon);

?>
Gave up on fsocket

Thanks for trying guys :)
Post Reply