Skip to main content
April 27, 2006
Answered

how WOULD i write this in Cold Fusion?

This is a PHP function that shows me how many users are in my chatroom, but I don't know how to do this in Cold Fusion. I need to in order to see who's in my chat room. Any ideas on how I'd do this?

Here's the working PHP code

<?
$port = 10010;
function getServerAPI( $apiCommand ) {
global $port;
$result = "";
$fp = fsockopen("localhost", $port, &$errno, &$errstr, 2);
if(!$fp) {
echo "$errstr ($errno)\n";
} else {
fputs($fp,"GET /?".$apiCommand." HTTP/1.0\n\n");
$header = true;
while(!feof($fp)) {
$line = fgets($fp,128);
if ( $header == false ) $result .= $line;
if ( trim($line) == "" ) $header = false;
}
fclose($fp);
}
return $result;
}

$userCount = getServerAPI( "api.UserCount" );
$roomList = getServerAPI( "api.RoomList" );
$PeopleInRoom = getServerAPI("api.PeopleInRoom=The%20Lobby" );

echo "<b>Users Online Now:</b> ".$PeopleInRoom."<br><br>";
?>
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
April 28, 2006
thank you! worked like a charm.

2 replies

Participating Frequently
April 27, 2006
Not PHP person. But from the common logic point's of view, it looks like they execute HTTP "GET" request to the local host.

Something like:

$userCount = getServerAPI( "api.UserCount" );

should be

<cfhttp method="get" url=" http://localhost/?api.UserCount" port="10010">
Translate
Correct answer
April 28, 2006
thank you! worked like a charm.
Translate