User Control Panel
Advertisements

HELP US, HELP YOU!

PHP knowing when my Perl bot is offline

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Help
View unanswered posts
Author Message
Schmexi
Newbie
Newbie


Joined: 02 Oct 2006
Posts: 7


PostPosted: Mon Oct 23, 2006 5:44 am    Post subject: PHP knowing when my Perl bot is offline Reply with quote

Hiya! Smile

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.

Any help would be great thanks. <3
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Mon Oct 23, 2006 12:38 pm    Post subject: Reply with quote

Hi,

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. ]
Back to top
mattaustin
Sentinel
Sentinel


Joined: 19 Jul 2004
Posts: 556
Location: Los Angeles, CA
Reputation: 50.7
votes: 1

PostPosted: Mon Oct 23, 2006 5:40 pm    Post subject: Reply with quote

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 ]
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Mon Oct 23, 2006 6:33 pm    Post subject: Reply with quote

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/
Back to top
Schmexi
Newbie
Newbie


Joined: 02 Oct 2006
Posts: 7


PostPosted: Wed Oct 25, 2006 4:40 am    Post subject: Reply with quote

Oh wow! Thank you so much guys! I'll get to work on that straight away!

That helped me alot. Smile Thanks!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Help All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group