Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bot stop working after some time! #854

Closed
arashnz opened this issue Sep 14, 2020 · 11 comments
Closed

bot stop working after some time! #854

arashnz opened this issue Sep 14, 2020 · 11 comments

Comments

@arashnz
Copy link

arashnz commented Sep 14, 2020

Hello,

I created a bot using madelineproto, It uses onUpdateNewMessage function , the problem is after some time it stopped working and I need to refresh PHP file so the but start running again, Is there any way to fix this issue ?
Should I put the php file in cron jobs ?

Here is some part of my code :

if (!file_exists('madeline.php')) {
    copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';

use danog\MadelineProto\EventHandler;
use danog\MadelineProto\Tools;
use danog\MadelineProto\API;
use danog\MadelineProto\Logger;
use danog\MadelineProto\RPCErrorException;


........ 


public function onUpdateNewMessage(array $update): \Generator
    {
        if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) {
            return;
        }
        $res = \json_encode($update, JSON_PRETTY_PRINT);

        yield $this->messages->sendMessage(['peer' => $update, 'message' => "<code>$res</code>", 'reply_to_msg_id' => $update['message']['id'] ?? null, 'parse_mode' => 'HTML']);
        if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') {
            yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]);

            yield $this->messages->sendMessage(['peer' => $update, 'message' => 'test', 'reply_to_msg_id' => $update['message']['id'] ?? null]);

            yield $this->downloadToFile($update, '10.mp3');


            $new = yield $this->downloadToDir($update, '/home/mpxxxxxxxxxx/public_html/bot/tmp/');

            yield $this->messages->sendMessage(['peer' => $update, 'message' => $new,'reply_to_msg_id' => $update['message']['id'] ?? null]);


        }
    }
}

$settings = [];

$MadelineProto = new API('bot.madeline', $settings);
$MadelineProto->startAndLoop(MyEventHandler::class);
@danog
Copy link
Owner

danog commented Sep 14, 2020

Please send full logs and make sure to use dev-master.

@arashnz
Copy link
Author

arashnz commented Sep 20, 2020

here is full logs :
logsbot.txt

@danog
Copy link
Owner

danog commented Sep 21, 2020

Well everything seems fine in the logs, does sending a raw HTTP payload via telnet to the host (port 80) like the one mentioned in the logs work?

GET /bot/mnewfile/mnewfile1.php?MadelineSelfRestart=6850746162700611757 HTTP/1.1
Host: yyyyyyyyyyyyy.com


(notice the double enter at the end)

@arashnz
Copy link
Author

arashnz commented Sep 23, 2020

The problem was from my hosting.
I run the php file from cron job and it works fine !

@itsMoji
Copy link

itsMoji commented Oct 8, 2020

@danog
I have this problem too on the latest dev-master.

Everything is working fine but after a few hours I've get this error and the event loop handler isn't working anymore, I've should restart the script to make it work again.

APIWrapper:             Saved session!
LoggerLoop, BOTUSERNAME:       Exited read loop in DC 4.0
ReadLoop, BOTUSERNAME:         danog\MadelineProto\NothingInTheSocketException in /home/itsmoji/madelineProto/new-2/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php:180
Stack trace:
#0 [internal function]: danog\MadelineProto\Stream\Common\BufferedRawStream->bufferReadGenerator()
#1 /home/itsmoji/madelineProto/new-2/src/danog/MadelineProto/Coroutine.php(116): Generator->send()
#2 /home/itsmoji/madelineProto/new-2/vendor/amphp/amp/lib/Internal/Placeholder.php(149): danog\MadelineProto\Coroutine->danog\MadelineProto\{closure}()
#3 /home/itsmoji/madelineProto/new-2/vendor/amphp/amp/lib/Deferred.php(52): class@anonymous->resolve()
#4 /home/itsmoji/madelineProto/new-2/vendor/amphp/byte-stream/lib/ResourceInputStream.php(101): Amp\Deferred->resolve()
#5 /home/itsmoji/madelineProto/new-2/vendor/amphp/amp/lib/Loop/NativeDriver.php(183): Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}()
#6 /home/itsmoji/madelineProto/new-2/vendor/amphp/amp/lib/Loop/NativeDriver.php(96): Amp\Loop\NativeDriver->selectStreams()
#7 /home/itsmoji/madelineProto/new-2/vendor/amphp/amp/lib/Loop/Driver.php(138): Amp\Loop\NativeDriver->dispatch()
#8 /home/itsmoji/madelineProto/new-2/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()
#9 /home/itsmoji/madelineProto/new-2/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run()
#10 /home/itsmoji/madelineProto/new-2/src/danog/MadelineProto/Tools.php(315): Amp\Loop::run()
#11 /home/itsmoji/madelineProto/new-2/src/danog/MadelineProto/API.php(306): danog\MadelineProto\Tools::wait()
#12 /home/itsmoji/services/forwardService.php(213): danog\MadelineProto\API->startAndLoop()
#13 {main}
ReadLoop, BOTUSERNAME:         Got nothing in the socket in DC 4.0, reconnecting...
Connection, BOTUSERNAME:       Reconnecting DC 4.0
Connection, BOTUSERNAME:       Disconnecting from DC 4.0
WriteLoop, BOTUSERNAME:        Exiting write loop in DC 4.0
LoggerLoop, BOTUSERNAME:       Exited write loop in DC 4.0
LoggerLoop, BOTUSERNAME:       Exited check loop in DC 4.0
Connection, BOTUSERNAME:       Disconnected from DC 4.0
DataCenter, BOTUSERNAME:       Reconnecting to DC 4 (0) from existing
DataCenterConnection, BOTUSERNAME:        Trying shared connection via tcp://149.154.167.91:443 main DC 4, via ipv4 using AbridgedStream => BufferedRawStream => DefaultStream (0)
Connection, BOTUSERNAME:       Connecting to DC 4.0
Connection, BOTUSERNAME:       Connected to DC 4.0!
LoggerLoop, BOTUSERNAME:       Entered write loop in DC 4.0
WriteLoop, BOTUSERNAME:        Waiting in write loop in DC 4.0
LoggerLoop, BOTUSERNAME:       Entered read loop in DC 4.0
LoggerLoop, BOTUSERNAME:       Entered check loop in DC 4.0
LoggerLoop, BOTUSERNAME:       Entered HTTP wait loop in DC 4.0
LoggerLoop, BOTUSERNAME:       Exited HTTP wait loop in DC 4.0
DataCenter, BOTUSERNAME:       OK!
APIWrapper:             Saved session!
APIWrapper:             Saved session!
APIWrapper:             Saved session!

Is this should be there?

@danog
Copy link
Owner

danog commented Oct 9, 2020

No fatal errors here, MadelineProto recovers from connection errors automatically

@arashnz
Copy link
Author

arashnz commented Oct 18, 2020

I find something new in log that cause the bot to don't work some times...

Exception:      	Undefined index: SERVER_NAME in Loop.php:120
[16-Oct-2020 09:28:02 UTC] PHP Fatal error:  Uncaught \danog\MadelineProto\Exception: Undefined index: SERVER_NAME in /home/yyyy/public_html/yyyy/vendor/danog/madelineproto/src/danog/MadelineProto/Wrappers/Loop.php:120

TL Trace:
<br>
Loop.php(120):      	exceptionErrorHandler(8,"Undefined index: SERVER_NAME","\/home\/yyyy\/public_html\\/vendor\/danog\/madelineproto\/src\/danog\/MadelineProto\/Wrappers\/Loop.php",120,{"logger":{"mode":2,"optional":"\/home\/yyyy\/public_html\//MadelineProto.log","prefix":", ","level":5,"colors":{"5":"37;2","4":"32;1","3":"33;1","2":"97;2;41","1":"97;1;41","0":"31;1;47"},"newline":"\n","stdout":{}}})<br>
Shutdown.php(53):   	danog\MadelineProto\Wrappers\{closure}()<br>
shutdown()
  thrown in /home/yyyy/public_html/yyyy/vendor/danog/madelineproto/src/danog/MadelineProto/Wrappers/Loop.php on line 120

any idea how to solve this ?

@danog
Copy link
Owner

danog commented Oct 23, 2020

Use danog/madelineproto:dev-master to fix this.

@danog danog closed this as completed Oct 23, 2020
@recoverjp
Copy link

The problem was from my hosting. I run the php file from cron job and it works fine !

Can you help me with this!?
Here i have the same problem
Did you manage to solve it?

@kemitrio
Copy link

hi
i have same problem
please help

@danog
Copy link
Owner

danog commented Dec 11, 2022

Please open a new issue with full logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants