Posted: Mon Oct 23, 2006 5:44 am Post subject: PHP knowing when my Perl bot is offline
Hiya!
I've been working on a little Perl bot for the past few weeks to expand my knowledge and all. It's going well.
At the moment I've got it uploading a few .ini files every so often to my website's FTP. These files contain information like how long the bot has been up for, and how many users are currently online.
Everything is going fine, but I can't figure out a way for my site to know when my bot is offline. I want to be able to display something like "The bot is currently online/offline". The only way I thought of was to upload a file when it goes off, so the PHP checks that file and displays the correct message, or something, but the main reason my bot would go down is because my internet disconnects, so I wouldn't be able to upload a file.
There are two ways really. The first is to get PHP to also be connected to the MSN servers and see when its buddy (the bot) is offline. This is hard to code and uses lots of system resources.
The other way is similar to yours mentioned, but instead of uploading a file when the bot goes offline, GET a PHP file every minute or so, so PHP can then tell when the bot is offline (as if the last GET was over a minute ago, it must be offline or malfunctioning). This is a bit like sending a PING to PHP and PHP sending a PONG back.
So,
- Every 60 seconds GET the PHP script
- In the PHP script, store the time of the last GET
- Output a 1 or 0 for Perl to use to see if it was successfully pinged
- When displaying whether the bot is on- or off-line, check to see if the time of the last GET was over 80 seconds (allowing for lag). If it was, the bot is offline. Else, it's online
Hope that helped =] _________________ ~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA votes: 1
Posted: Mon Oct 23, 2006 5:40 pm Post subject:
I think i would use a database or a file... and have the perl bot every 5 seconds using LWP::Simple:
get('http://someserver/ping.php');
that php would write the time stamp to a file or DB
then your "is online" script would just check that the time stamp in the file or DB is within the last 5 seconds.
If it didn't "check in" in the last 5 seconds its not online.
(you could also pass to your "ping script" the number of current users and things like that so you dont have to upload files via FTP. ex: ping.php?users=3&uptime=1000) _________________ [ matt ]
Pinging every 5 seconds might be a bit of overkill, considering the CPU cycles it takes to open and close a socket. I'd say 15 seconds minimum, and for your site, allow at least half the amount of twice the ping time (if the bot pings every 15 seconds, allow 20 to 25 seconds for lag before marking the bot as offline). _________________ Current Site (2008) http://www.cuvou.com/