danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.8k stars 636 forks source link

Multiple tables in MySQL database #1371

Closed Kamran1991 closed 1 year ago

Kamran1991 commented 1 year ago

Hi @danog I'm using MadelineProto in Laravel using Docker. I need to store unique telegram sessions for multiple users. Previously I was not using a database and so I was facing memory issues but now I am using MYSQL as per documentation (https://docs.madelineproto.xyz/docs/DATABASE.html). Still, session files are getting created in my project directory, and I can see a lot of tables in the database as well. is it normal to have multiple tables in a database? How can i prevent MadelineProto from creating session files in the project directory?

Session files in the project directory image

Tables in database image

Here is the code, you can see the phoneLogin method in the below code

       $appInfo = new AppInfo;
        $appInfo->setApiId(env('MP_TELEGRAM_API_ID'));
        $appInfo->setApiHash(env('MP_TELEGRAM_API_HASH'));
        $this->settings = new Settings;
        $this->settings->setAppInfo($appInfo);
       $dbInfo = new Mysql;

        $dbInfo->setUri(env('DB_HOST_URI'));
        $dbInfo->setDatabase(env('DB_DATABASE'));
        $dbInfo->setUsername(env('DB_USERNAME'));
        $dbInfo->setPassword(env('DB_PASSWORD'));
         $this->settings->setDb($dbInfo);
         array_map('unlink', glob($user->id."session.madeline*"));
          $madelineProto = new \danog\MadelineProto\API($user->id.'session.madeline', $this->settings);
          $madelineProto->phoneLogin($phone); 
qwillio-live commented 1 year ago

@danog can you help with this? I faced the same issue

danog commented 1 year ago

First of all, please switch to MadelineProto 8, MadelineProto 7 has some severe bugs that were fixed in v8.

Regarding the files: it's normal, they still will be created even when using the DB, but they will be a lot smaller (a few kb, mostly containing db connection URIs+IPC sockets), and all of the actual session data will be stored in the database (in multiple tables, yes, which is why I also recommend creating a separate database just for MadelineProto).