unreal4u / telegram-api

Complete async capable Telegram bot API implementation for PHP7
https://github.com/unreal4u/telegram-api/wiki
MIT License
784 stars 172 forks source link

Fatal Error: Out Of Memory When i trying to send video #132

Closed anajo333 closed 3 years ago

anajo333 commented 3 years ago

Hello, i using a lastest version from telegram-api

I want to upload video 192MB and send it to my channel with examples/send-video.php i change $sendVideo->video = new InputFile('binary-test-data/demo-video.mp4'); to my file but this error faced me

fatal error: out of memory (allocated 1613365248) (tried to allocate 201413288 bytes) in /home/ooo/public_html/2/src/InternalFunctionality/PostOptionsConstructor.php

I added

ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
set_time_limit(0);

in the top of scripts like

examples/send-video.php examples/basics.php src/InternalFunctionality/PostOptionsConstructor.php examples/config.php vendor/autoload.php

And this error still faced me i tryed on too many servers There's any solve for this problem

DJTommek commented 3 years ago

Your issue is your-server-related. I tried your example with 188mb file on notebook with 16 GB RAM and it went thru PHP just fine. I guess that you are limited by hardware capability provided on your server.

Anyway, even if you would solve out of memory issue, Telegram API is not accepting uploaded files that big, as you can see here: https://core.telegram.org/bots/api#sending-files

Post the file using multipart/form-data in the usual way that files are uploaded via the browser. 10 MB max size for photos, 50 MB for other files.

If you send file bigger than that, Telegram API will respond with:

413: Request Entity Too Large

And this library will throw this exception:

\unreal4u\TelegramAPI\Exceptions\ClientException: Request Entity Too Large #413

If you try something smaller (for example 2.9 MB) PHP will upload it correctly and Telegram will accept it as it should. Only solution that came up in my mind is using recently introduced Local Bot API Server, which increasing limit up to 2000 MB. According issue #129 it should be possible with this library but I didn't tested it, yet.

unreal4u commented 3 years ago

Very good answer @DJTommek ! Thanks for answering this!