mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 23:14:38 +01:00
Allow uploading PHP memory resources and add reportMemoryProfile method
This commit is contained in:
parent
7c14ff9924
commit
30890ae4e5
@ -677,6 +677,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.reportProfilePhoto.html" name="account.reportProfilePhoto">Report a profile photo of a dialog: account.reportProfilePhoto</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.reportEncryptedSpam.html" name="messages.reportEncryptedSpam">Report a secret chat for spam: messages.reportEncryptedSpam</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#report-string-message-string-parsemode-void" name="report">Report an error to the previously set peer: report</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#reportmemoryprofile-void" name="reportMemoryProfile">Report: reportMemoryProfile</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.reportSpam.html" name="channels.reportSpam">Reports some messages from a user in a supergroup as spam; requires administrator rights in the supergroup: channels.reportSpam</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getEmojiGroups.html" name="messages.getEmojiGroups">Represents a list of emoji categories, to be used when selecting custom emojis: messages.getEmojiGroups</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getEmojiStatusGroups.html" name="messages.getEmojiStatusGroups">Represents a list of emoji categories, to be used when selecting custom emojis to set as custom emoji status: messages.getEmojiStatusGroups</a>
|
||||
|
2
docs
2
docs
@ -1 +1 @@
|
||||
Subproject commit 2a68e556a694b0f87168afb4a2a6915d7962ca8c
|
||||
Subproject commit b190279913a2383235d7af8b6947067fbb5b956d
|
@ -1395,6 +1395,13 @@ abstract class InternalDoc
|
||||
{
|
||||
$this->wrapper->getAPI()->report($message, $parseMode);
|
||||
}
|
||||
/**
|
||||
* Report memory profile with memprof.
|
||||
*/
|
||||
public function reportMemoryProfile(): void
|
||||
{
|
||||
$this->wrapper->getAPI()->reportMemoryProfile();
|
||||
}
|
||||
/**
|
||||
* Request VoIP call.
|
||||
*
|
||||
@ -1717,12 +1724,12 @@ abstract class InternalDoc
|
||||
/**
|
||||
* Upload file.
|
||||
*
|
||||
* @param FileCallbackInterface|string|array $file File, URL or Telegram file to upload
|
||||
* @param FileCallbackInterface|string|array|resource $file File, URL or Telegram file to upload
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*/
|
||||
public function upload(\danog\MadelineProto\FileCallbackInterface|array|string $file, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
{
|
||||
return $this->wrapper->getAPI()->upload($file, $fileName, $cb, $encrypted);
|
||||
}
|
||||
|
@ -88,6 +88,9 @@ final class WebRunner extends RunnerAbstract
|
||||
'argv' => ['madeline-ipc', $session, $startupId],
|
||||
'cwd' => Magic::getcwd(),
|
||||
];
|
||||
if (\function_exists('memprof_enabled') && \memprof_enabled()) {
|
||||
$params['MEMPROF_PROFILE'] = '1';
|
||||
}
|
||||
|
||||
self::selfStart(self::$runPath.'?'.\http_build_query($params));
|
||||
|
||||
|
@ -1695,6 +1695,37 @@ final class MTProto implements TLCallback, LoggerGetter
|
||||
$lock->release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Report memory profile with memprof.
|
||||
*/
|
||||
public function reportMemoryProfile(): void
|
||||
{
|
||||
if (!\extension_loaded('memprof')) {
|
||||
throw Exception::extension('memprof');
|
||||
}
|
||||
if (!\memprof_enabled()) {
|
||||
throw new Exception("Memory profiling is not enabled in the database settings, set the MEMPROF_PROFILE=1 environment variable or GET parameter to enable it.");
|
||||
}
|
||||
|
||||
$current = "Current memory usage: ".\round(\memory_get_usage()/1024/1024, 1) . " MB";
|
||||
$file = \fopen('php://memory', 'r+');
|
||||
\memprof_dump_pprof($file);
|
||||
\fseek($file, 0);
|
||||
$file = [
|
||||
'_' => 'inputMediaUploadedDocument',
|
||||
'file' => $file,
|
||||
'attributes' => [
|
||||
['_' => 'documentAttributeFilename', 'file_name' => 'report.pprof'],
|
||||
],
|
||||
];
|
||||
foreach ($this->reportDest as $id) {
|
||||
try {
|
||||
$this->methodCallAsyncRead('messages.sendMedia', ['peer' => $id, 'message' => $current, 'media' => $file]);
|
||||
} catch (Throwable $e) {
|
||||
$this->logger("While reporting memory profile to $id: $e", Logger::FATAL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get full list of MTProto and API methods.
|
||||
*/
|
||||
|
@ -229,12 +229,12 @@ trait FilesLogic
|
||||
/**
|
||||
* Upload file.
|
||||
*
|
||||
* @param FileCallbackInterface|string|array $file File, URL or Telegram file to upload
|
||||
* @param FileCallbackInterface|string|array|resource $file File, URL or Telegram file to upload
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback (DEPRECATED, use FileCallbackInterface)
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*/
|
||||
public function upload(FileCallbackInterface|string|array $file, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
{
|
||||
if (\is_object($file) && $file instanceof FileCallbackInterface) {
|
||||
$cb = $file;
|
||||
|
@ -215,7 +215,9 @@ trait UpdateHandler
|
||||
if (!$this->updates) {
|
||||
try {
|
||||
$this->update_deferred = new DeferredFuture();
|
||||
$this->update_deferred->getFuture()->await(new TimeoutCancellation($timeout));
|
||||
$this->update_deferred->getFuture()->await(
|
||||
$timeout === INF ? null : new TimeoutCancellation($timeout)
|
||||
);
|
||||
} catch (CancelledException $e) {
|
||||
if (!$e->getPrevious() instanceof TimeoutException) {
|
||||
throw $e;
|
||||
|
@ -853,7 +853,7 @@ interface Messages
|
||||
* @param bool $update_stickersets_order Whether to move used stickersets to top, [see here for more info on this flag »](https://core.telegram.org/api/stickers#recent-stickersets)
|
||||
* @param int $reply_to_msg_id The message to reply to
|
||||
* @param int $top_msg_id This field must contain the topic ID **only** when replying to messages in [forum topics](https://core.telegram.org/api/forum#forum-topics) different from the "General" topic (i.e. `reply_to_msg_id` is set and `reply_to_msg_id != topicID` and `topicID != 1`). <br>If the replied-to message is deleted before the method finishes execution, the value in this field will be used to send the message to the correct topic, instead of the "General" topic.
|
||||
* @param list<array{_: 'inputSingleMedia', media: string|array, message?: string, entities?: list<array{_: 'messageEntityUnknown', offset?: int, length?: int}|array{_: 'messageEntityMention', offset?: int, length?: int}|array{_: 'messageEntityHashtag', offset?: int, length?: int}|array{_: 'messageEntityBotCommand', offset?: int, length?: int}|array{_: 'messageEntityUrl', offset?: int, length?: int}|array{_: 'messageEntityEmail', offset?: int, length?: int}|array{_: 'messageEntityBold', offset?: int, length?: int}|array{_: 'messageEntityItalic', offset?: int, length?: int}|array{_: 'messageEntityCode', offset?: int, length?: int}|array{_: 'messageEntityPre', offset?: int, length?: int, language?: string}|array{_: 'messageEntityTextUrl', offset?: int, length?: int, url?: string}|array{_: 'messageEntityMentionName', offset?: int, length?: int, user_id?: int}|array{_: 'inputMessageEntityMentionName', user_id: array|int|string, offset?: int, length?: int}|array{_: 'messageEntityPhone', offset?: int, length?: int}|array{_: 'messageEntityCashtag', offset?: int, length?: int}|array{_: 'messageEntityUnderline', offset?: int, length?: int}|array{_: 'messageEntityStrike', offset?: int, length?: int}|array{_: 'messageEntityBlockquote', offset?: int, length?: int}|array{_: 'messageEntityBankCard', offset?: int, length?: int}|array{_: 'messageEntitySpoiler', offset?: int, length?: int}|array{_: 'messageEntityCustomEmoji', offset?: int, length?: int, document_id?: int}>}>|array<never, never> $multi_media Array of The medias to send: note that they must be separately uploaded using [messages.uploadMedia](https://docs.madelineproto.xyz/API_docs/methods/messages.uploadMedia.html) first, using raw `inputMediaUploaded*` constructors is not supported. @see https://docs.madelineproto.xyz/API_docs/types/InputSingleMedia.html
|
||||
* @param list<array{_: 'inputSingleMedia', media: string|array, message?: string, entities?: list<array{_: 'messageEntityUnknown', offset?: int, length?: int}|array{_: 'messageEntityMention', offset?: int, length?: int}|array{_: 'messageEntityHashtag', offset?: int, length?: int}|array{_: 'messageEntityBotCommand', offset?: int, length?: int}|array{_: 'messageEntityUrl', offset?: int, length?: int}|array{_: 'messageEntityEmail', offset?: int, length?: int}|array{_: 'messageEntityBold', offset?: int, length?: int}|array{_: 'messageEntityItalic', offset?: int, length?: int}|array{_: 'messageEntityCode', offset?: int, length?: int}|array{_: 'messageEntityPre', offset?: int, length?: int, language?: string}|array{_: 'messageEntityTextUrl', offset?: int, length?: int, url?: string}|array{_: 'messageEntityMentionName', offset?: int, length?: int, user_id?: int}|array{_: 'inputMessageEntityMentionName', user_id: array|int|string, offset?: int, length?: int}|array{_: 'messageEntityPhone', offset?: int, length?: int}|array{_: 'messageEntityCashtag', offset?: int, length?: int}|array{_: 'messageEntityUnderline', offset?: int, length?: int}|array{_: 'messageEntityStrike', offset?: int, length?: int}|array{_: 'messageEntityBlockquote', offset?: int, length?: int}|array{_: 'messageEntityBankCard', offset?: int, length?: int}|array{_: 'messageEntitySpoiler', offset?: int, length?: int}|array{_: 'messageEntityCustomEmoji', offset?: int, length?: int, document_id?: int}>}>|array<never, never> $multi_media Array of The medias to send @see https://docs.madelineproto.xyz/API_docs/types/InputSingleMedia.html
|
||||
* @param int $schedule_date Scheduled message date for scheduled messages
|
||||
* @param array|int|string $send_as Send this message as the specified peer @see https://docs.madelineproto.xyz/API_docs/types/InputPeer.html
|
||||
* @return array @see https://docs.madelineproto.xyz/API_docs/types/Updates.html
|
||||
|
@ -12,6 +12,9 @@ function mergeExtracted(): void
|
||||
return;
|
||||
}
|
||||
foreach (json_decode(file_get_contents('extracted.json'), true) as $key => $value) {
|
||||
if ($key === 'method_messages.sendMultiMedia_param_multi_media_type_Vector<InputSingleMedia>') {
|
||||
$value = 'The medias to send';
|
||||
}
|
||||
$key = preg_replace(['|flags\.\d+[?]|', '/Vector[<].*/'], ['', 'Vector t'], $key);
|
||||
$key = str_replace('param_hash_type_int', 'param_hash_type_Vector t', $key);
|
||||
Lang::$lang['en'][$key] = $value;
|
||||
|
Loading…
Reference in New Issue
Block a user