core: Memory Leak in HandleGetUpdates() ???

Hi,

just implemented a small daemon based on php-telegram-bot to receive text messages sent to my bot.

I realized, that the memory usage is steadily growing, up to 100% if you are waiting for a while (depending on the memory you have installed).

Here is my code:

<?php 

set_time_limit(0);

require (dirname(__FILE__)."/php-telegram-bot/vendor/autoload.php");

use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\InlineQuery;


$apiKey = '#######################################################';
$botName = '*********';

$telegram = new Telegram($apiKey, $botName);

// Enable MySQL
$mysql_credentials = array(
    'host'     => '127.0.0.1',
    'user'     => 'root',
    'password' => '########',
    'database' => 'Telegram',
);
$telegram->enableMySQL($mysql_credentials);

// polling for new messages
while (1)
{
    $serverResponse = $telegram->handleGetUpdates();
    if ($serverResponse->isOk()) 
    {
        $receivedTelegrams = $serverResponse->getResult();
        if (count($receivedTelegrams))
        {
            foreach ($receivedTelegrams as $tg)
            {
                $updateContent = $tg->getUpdateContent();
                if ($updateContent instanceof Longman\TelegramBot\Entities\Message)
                {
                    $text = preg_replace('/\s+/', ' ',trim(strtoupper($updateContent->getText())));
                    $chatId = $updateContent->getFrom()->getId();
                } else if ($updateContent instanceof Longman\TelegramBot\Entities\InlineQuery)
                {
                    $text = preg_replace('/\s+/', ' ',trim(strtoupper($updateContent->getQuery())));
                    $chatId = $updateContent->getFrom()->getId();
                } else if ($updateContent instanceof Longman\TelegramBot\Entities\ChosenInlineResult)
                {
                    $text = preg_replace('/\s+/', ' ',trim(strtoupper($updateContent->getQuery())));
                    $chatId = $updateContent->getFrom()->getId();
                }
                echo "$chatId: $text\n";
            }
        }
    }
    usleep(100000);
}


?>

Any ideas, where could be the problem?

Best regards André

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 25 (9 by maintainers)

Most upvoted comments

@MBoretto according to this page I think you need to close $verbose temp file.

I also suggest close curl handler before throwing TelegramException. I can catch that exception, but $ch still opened

But not sure if it only the reason

@MBoretto: How can I use it without database? My understanding was, when using in polling mode, I have to use the database, right?