TGViewer
MadelineProto | Official Channel MadelineProto | Official Channel @madelineproto · 6.42K subscribers
Post #446 3.91K
- Async forking (does async green thread forking)

Useful if you need to start a process in the background and you want throwed exceptions to surface up.
These exceptions will exit the event loop, turning off the script unless you wrap $MadelineProto->loop() with a try-catch.
Use it when you do not need the result of a method (see ignored async), but you want eventual errors to crash the script.
Otherwise, just use the method without yield.


// Exceptions will surface out of the event loop()
$MadelineProto->callFork($MadelineProto->messages->sendMessage([...]));
// Exceptions will be ignored
$MadelineProto->messages->sendMessage([...]);

// Like the first one, but the call will be deferred to the next event loop tick
$MadelineProto->callForkDefer($MadelineProto->messages->sendMessage([...]));


- I also created some wrapper functions to work asynchronously with console/browser output
Async sleep:
yield $MadelineProto->sleep(3);

Async readline:
$res = yield $MadelineProto->readLine('Optional prompt');


- Logging is now completely asynchronous and easier:
$MadelineProto->logger("Message");


No need to yield here, because the logging must be done in background.

- Simultaneous method calls:
yield $MadelineProto->messages->sendMessage([
'multiple' => true,
['peer' => '@danogentili', 'message' => 'hi'],
['peer' => '@apony', 'message' => 'hi']
]);


This is the preferred way of combining multiple method calls: this way, the MadelineProto async WriteLoop will combine all method calls in one container, making everything WAY faster.
The result of this will be an array of results, whose type is determined by the original return type of the method (see API docs).

The order of method calls can be guaranteed (server-side, not by MadelineProto) by using call queues.

- Exceptions:

NOTE: Due to the async nature of MadelineProto 4.0, sometimes the exception that is thrown and logged may not be the actual exception that caused the crash of the script.
To let me properly debug the issue, when reporting issues you also have to provide full logs.

- Finally, async loops.

MadelineProto provides some very useful async loop APIs, for executing operations periodically or on demand.

They are the perfect solution for implementing async cron loops, signal threads and much more!
I'll just link you all to the documentation: it has full examples for each and every async API (you can also check out the code, it's full of PHPDOC comments).
More from @madelineproto
  1. Oct 17, 2026Introducing MadelineProto 8.8.8, with video calls, group calls, livestreams and end-to-end…
  2. Oct 17, 2026Introducing MadelineProto 8.8.8, with video calls, group calls, livestreams and end-to-end…
  3. Jul 26, 2026Native, pure-PHP (no FFI, no shell, 💯 webhost support) group and video calls are working…
  4. Jun 16, 2026MadelineProto may also be affected if your upstreams aren't filtering invalid routes via R…
  5. Jun 16, 2026Indeed, looking at the announced routes i.e. in https://bgp.he.net/AS18101#_prefixes + htt…
  6. Jun 16, 2026⚠️ Indian telecom Reliance is sabotaging access to Telegram for millions of users OUTSIDE…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →