PHP API - Get user daily, monthly, yearly report

Hi, im new to Mikrotik PHP API, am building an web application to display resources. Now I already have CPU, User Active, DHCP Lease and CPU Load. Now im trying to get total users online per day and save it to my database so that i can print a monthly, yearly report of total users online. Is there any API or alternative workaround to do this? Really appreciate your help. Thanks !

How would you do that if you were to do it “manually”? Be it with Winbox or (better yet) terminal?

(I’m asking specifically to figure out how you define “user” and “day”)

I searched all over google and found no answer, is it impossible to do this? Im thinking of on user login, I want to run a script to record userid and datetime and save it to my database. But, it seems illogical because there’s no way to connect my MySql database to the userman database right?

So “User Manager” users, got it. That’s very important.
(There are hotspot users, PPPoE users, users from an external RADIUS server… all of these require different approaches)

For “User Manager”, you can use

/tool/user-manager/session/listen

to listen for any new sessions.

When users log in, a session will become “active” (you’ll see the reply that has a property “active” with a value “true”). When they log out or their session expires, you’ll get another reply with a property called “dead” with a value “yes”.

Setup a script that will continuously monitor this (not a web page; a script triggered from the command line, in the background ideally…), and modifies your DB accordingly.