What php function would you use to show how many people are connected to a certain server? I was planning on showing if the server was online or not, and showing how many users are there.
What php function would you use to show how many people are connected to a certain server? I was planning on showing if the server was online or not, and showing how many users are there.
mysql,mssql?
also if it is a gaming server on which game?
i have that for L2J mysql.. but for which game u need that?
It's MySQL
Is there a way to check how many active connections there are to a port and use that to display the amount of users?
This shell command will store the number of users currently connected to a certain port in a file named 'numusers'. Either put it in the crontab to run every minute or a shell script to be called from the PHP script.In your PHP script, use the file functions to display the contents of the file above.Code:netstat -a -n | grep port_goes_here | wc -l > numusers
These is no way to do this on pure PHP?
and Could you chose what IP to listen on as well as what port? Because I have different servers on different computers and I would have to do this on every computer then.
I doubt it. Apache in any case creates a new instance for each request host, and doesn't register how many instances there are, not in the $_SERVER global anyway.
You could execute username1's script yourself without the write to file and simply turn output buffering on to directly get the data btw, but thats about as efficient as it gets :smile:
Oh. Well I have never used Shell scripts before. could you guys tell me where to put them and execute them?
Learn some *nix and read this: http://www.freeos.com/guides/lsst/
<?php
$string = exec("netstat -a -n | grep port_goes_here | wc -l > numusers");
?>
Then you just need to preg_match/ereg the string with the REGEX and you will be able to see the numbers. :)
Carefull with long exec statements, they tend to crash your server if the client is disconnect halfway trough or the script fails to run. Seems unlikely for short commands, but I've had it crash an apache server for only getting a directory listing. There are ways to let PHP continue to run while the script is being executed, as I've mentioned output buffering is one of them, I suggest you look into that :smile:
Also, with quite static data like this its better to either get the n'th character of your string ($string[n] will do that nicely for you) or, if you have to, use strstr since its a lot faster then a regexp:(And not to mention a LOT easier to get rightOriginally Posted by PHP.net
)
Last edited by FragFrog; 09-01-07 at 07:15 AM.
I need a same sample but for MSSQL (Game: GunZ). I tryed <?php
$string = exec("netstat -a -n | grep port_goes_here | wc -l > numusers");
?> but doesnt works. Thanks.
Depends what type of server....
MuQuery = SELECT connectstat FROM MEMB_INFO WHERE connectstat='1'