tags:

views:

64

answers:

3

I created a simple xmpp bot in PHP which connects to google talk server. I basically modified the cli_longrun example. When I run the script in browser the bot comes online and stays online for a while even after I close the tab on which the script was running (as it is just an infinite loop listening for events on the stream). But after a while the bot becomes offline.

The question is how do I keep the bot always online. One way I can think of is to run a cron that would disconnect the earlier one and start a new session. But is there a better approch?

+1  A: 

Run it from the command line and make sure your script doesn't end. Make sure you set_time_limit to 0 to keep it from killing itself.

Dianoga
+2  A: 

Run it from a command line, as long as the script doesn't break it'll stay running as long as the prompt is open.

If this is on a shared host, most likely they have measures in place to prevent a script from running forever even if you have set_time_limit(0) -- so you might be out of luck.

evolve
And even then from the command line you'll have to use **nohup**, otherwise it might end after you disconnect. Most shared hosts will also end processes that run for too long.
Konerak
+1  A: 

Might also respawn the script with a crontab entry of "@reboot sleep 300; ./runbot.sh" in your crontab if you are allowed cron access.

hpavc
yes thanks. that's definitely a todo. I keep forgetting such edge cases :)
Gunjan