Debian PHP jabber client deamon

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have written a rather simple php script using class_jabber.php
( ). It just logs in as a bot, and keeps track of
the on/offline status of our support staff (writing to a firebird2
table). It works fine as is when it's running.

The problem is that the daemon will stop working (exits memory) without
any trace in the log files after seemingly random amounts of time.

I use set_time_limit(0); to prevent PHP stopping the script. I have put
up signal handlers (I know that some signals aren't supposed to be

Here's some code from the php script:

function sig_handler($signo) {
  switch ($signo) {
    case SIGTERM:
    case SIGSTOP:
    case SIGKILL:
    case SIGINT:
      // handle shutdown tasks
      error_log(date('\[d-m-Y H:i:s\] ') . "Received TERM signal.\r\n",
3, $logfile);
      $jab->terminated = true;
      // disconnect from the Jabber server
      // update database, all unavailable when bot exits
    case SIGHUP:
      // handle restart tasks
      // handle all other signals
    // setup signal handlers
    pcntl_signal(SIGTERM, "sig_handler");
    pcntl_signal(SIGSTOP, "sig_handler");
    pcntl_signal(SIGKILL, "sig_handler");
    pcntl_signal(SIGINT, "sig_handler");

    define("CBK_FREQ", 1);     // fire a callback event every second

    // create an instance of the Jabber class
    $jab = new Jabber(false);
    // create an instance of our event handler class
    $test = new TestMessenger($jab);
    // set handlers for the events we wish to be notified about
    $jab->set_handler("connected", $test, "handleConnected");
    $jab->set_handler("authenticated", $test, "handleAuthenticated");
    $jab->set_handler("authfailure", $test, "handleAuthFailure");
    $jab->set_handler("heartbeat", $test, "handleHeartbeat");
    $jab->set_handler("error", $test, "handleError");
    $jab->set_handler("message_normal", $test, "handleMessage");
    $jab->set_handler("message_chat", $test, "handleMessage");
    // connect to the Jabber server
    if (!$jab->connect(JABBER_SERVER)) {
       die("Could not connect to the Jabber server!\n");
    // now, tell the Jabber class to begin its execution loop
    // Note that we will not reach this point (and the execute() method  
    // will not
    // return) until $jab->terminated is set to TRUE.  The execute()  
    // method simply
    // loops, processing data from (and to) the Jabber server, and  
    // firing events
    // (which are handled by our TestMessenger class) until we tell it  
    // to terminate.
    // This event-based model will be familiar to programmers who have  
    // worked on
    // desktop applications, particularly in Win32 environments.
    // disconnect from the Jabber server
    // update database, all unavailable when bot exits
    error_log(date('\[d-m-Y H:i:s\] ') . "Stopped.\r\n", 3, $logfile);

Here's the daemon script for running it in Debian (etch).

#! /bin/sh
# supportbotd   initscript
#               script for a php-based jabber control bot
# Author:       Sabine Dinis Blochberger, Op3racional.

set -e

DESC="IM support bot"

# Gracefully exit if the package has been removed.
#test -x $DAEMON || exit 0

# Read config file if it is present.
#if [ -r /etc/default/$NAME ]
#       . /etc/default/$NAME

#       Function that starts the daemon/service.
d_start() {
        start-stop-daemon --start --quiet --background \
                --make-pidfile --pidfile $PIDFILE \
                --exec /usr/bin/php $DAEMON &

#       Function that stops the daemon/service.
d_stop() {
        start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                 --signal SIGTERM  

#       Function that sends a SIGHUP to the daemon/service.
d_reload() {
        start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                --name $NAME --signal 1

case "$1" in
        echo -n "Starting $DESC: $NAME"
        echo "."
        echo -n "Stopping $DESC: $NAME"
        echo "."
        #       If the daemon can reload its configuration without
        #       restarting (for example, when it is sent a SIGHUP),
        #       then implement that here.
        #       If the daemon responds to changes in its config file
        #       directly anyway, make this an "exit 0".
        # echo -n "Reloading $DESC configuration..."
        # d_reload
        # echo "done."
        #       If the "reload" option is implemented, move the
        #       option to the "reload" entry above. If not,
"force-reload" is
        #       just the same as "restart".
        echo -n "Restarting $DESC: $NAME"
        sleep 1
        echo "."
        # echo "Usage: $SCRIPTNAME
" >&\
        echo "Usage: $SCRIPTNAME " >&2
        exit 1

exit 0

Note that stopping via this bash script doesn't work. I have to kill -9
the process. Any help on either these codes is appreciated. Thanks :)

PHP version is 5.

Re: Debian PHP jabber client deamon

Sabine Dinis Blochberger wrote:

Quoted text here. Click to load it
Is there a way at least to restart the process once it leaves memory?


Site Timeline