Accounting Daemon

Hi Guys

I am busy writing a script that grabs information for all the users on my RB1100 and then writing it to a MySQL database. Since it writes more that 500 lines per second (Yes I know), I have a second script that runs every 5 minutes. This script I called “historical data”. It calculates all the bytes for each user in the first table, then writes it in the historical data table from which I read when I do reporting.

Now, the only language I know is PHP. I write the daemon also in PHP, but it only runs for a few hours and then some times crashes or just stops polling the router.

I need to get a more reliable method of reading the accounting for my l2tp users. I will share the code for my scripts here so you guys can see what it is I am doing.

This is the link to the data collector which query’s the mikrotik’s accounting table.
http://pastie.org/6623549

The data collector daemon and RB1100 is not on the same physical network. I believe that the $API->connect() function should sit inside the endless loop of the daemon. Could this be the problem?

Thanks for the help.

You’re connecting from the parent process, and although you have an exit statement, perhaps PHP is closing the connection there… or rather, waiting for it to become idle before it closes it, which is likely to happen sooner or later.

Assuming this is the case, the remedy should be to simply open the connection from the child process. Not within the endless loop though. Just before it, i.e.

} else {
        //We're now in the child process.

        //Now, we detach from the terminal window, so that we stay alive when
        //it is closed.
        if ( posix_setsid() == -1 ) {
               echo "\n Error: Unable to detach from the terminal window. \n";
        }
        //Get out process id now that we've detached from the window.
        $posixProcessID = posix_getpid();
        $API->connect($router_address, $router_username, $router_password); 

P.S. As a fellow advanced PHP user, I’d really appreciate your opinion on my client. If the solution above doesn’t cut it, I’d also propose trying with it.