venomous0x / WhatsAPI

Interface to WhatsApp Messenger
2.59k stars 2.13k forks source link

Keep bot online #584

Open ghost opened 10 years ago

ghost commented 10 years ago

Hi,

I've a problem. The bot keeps online for max 1 hour. After this hour the bot goes offline and doesn't come back online. It only goes offline if i reload the script. How can i fix this?

Grtz,

Matthijs

jesussales commented 10 years ago

Hello! I think is better that you connect, collect messages, logout every x minutes, you can programming a cron task for this work

Saludos Jesús Sales

El 16/01/2014, a las 19:25, Matthijs Otterloo notifications@github.com escribió:

Hi,

I've a problem. The bot keeps online for max 1 hour. After this hour the bot goes offline and doesn't come back online. It only goes offline if i reload the script. How can i fix this?

Grtz,

Matthijs

— Reply to this email directly or view it on GitHub.

ghost commented 10 years ago

Okay, so i have to make a cron job to restart the script every few seconds?

zephyern commented 10 years ago

I'm able to stay logged in for days without disconnecting. How often are you polling? Are you responding to the ping messages?

ghost commented 10 years ago

This is my code: http://pastebin.com/ZGyBDD0Z 123 are placeholders..... What do i have to change in my code to fix this?

shirioko commented 10 years ago

Increase the value in

set_time_limit(10);

in line 2.

e.g.

set_time_limit(300);//5 minutes
ghost commented 10 years ago

@shirioko what if i want the bot 24/7 online?

jesussales commented 10 years ago

24h per day over 7 days

Saludos Jesús Sales

El 19/01/2014, a las 22:54, Matthijs Otterloo notifications@github.com escribió:

@shirioko what if i want the bot 24/7 online?

— Reply to this email directly or view it on GitHub.

ghost commented 10 years ago

Nope, changing the set_time_limit(10); to set_time_limit(300); doesn't work…. Any other ideas?

shirioko commented 10 years ago

What does your debug output say?

8DigitalStaging commented 10 years ago

Well? What is the best way to stop it from stopping, and have the bot running forever? set_time_limit(0) and change php max_execution time to 0?

mgp25 commented 10 years ago

and sendPresence so it doesnt close socket

8DigitalStaging commented 10 years ago

How do you set up sendPresence? I havent come across that function yet...

mgp25 commented 10 years ago

whatsprot.class for more info

$w->sendPresence();
8DigitalStaging commented 10 years ago

Thanks. So would I need to run the function every so often? I am guessing that this function needs to keep being called every now and again....

shirioko commented 10 years ago

sendPresence() won't keep you online.

CharlesOkwuagwu commented 10 years ago

@shirioko @mgp25 This seems to be a common request/question. "How do we stay connected", i.e Keep the connection or "BOT" from going offline.

Can we please get a definitive answer. Thanks.

EDIT: in my tests, sendPresence() with no other activity, sent once every 60secs will keep you online for 10 mins MAX

shirioko commented 10 years ago

I already addressed this issue in WhatsApiNet

CharlesOkwuagwu commented 10 years ago

i use WhatsApiNet, i am having the same issue, can you please point to the write usage?

thanks.

mgp25 commented 10 years ago

Why dont you search it in WhatsApiNet repo instead of asking here?

CharlesOkwuagwu commented 10 years ago

seen. thanks.

8DigitalStaging commented 10 years ago

@cahrlesokwuagwu before you gallop off into the sunset....could you share where you "seen" it. Thanks!

mgp25 commented 10 years ago

@8DigitalStaging Find it in WhatsApiNet repo, the information is in there, why dont you search there?

8DigitalStaging commented 10 years ago

I am but a link to the exact one would be so much quicker.....

mgp25 commented 10 years ago

I know, but people needs to start searching for themselfes

8DigitalStaging commented 10 years ago

for all those who come here searching https://github.com/perezdidac/WhatsAPINet/issues/116

8DigitalStaging commented 10 years ago

But still all that code is .net Is there no simple solution in PHP? keepAlive() function or something? This is the last peice to my puzzle and is vital for my project to work.

mgp25 commented 10 years ago

You dont know how to search... here

There are workarounds, but you can code it the way you want

8DigitalStaging commented 10 years ago

Thanks. The .net version is calling SendGetPrivacySettings() which does not exist in the PHP version. I am assuming I can use any sendget function desired just to keep server communication open?

shirioko commented 10 years ago

No you can use sendGetPrivacyBlockedList instead

8DigitalStaging commented 10 years ago

Thanks. Testing the threading I have extended processnode function with thread and now it throws an error on the class saying class not found. Fatal error: Class 'ProcessNode' not found

8DigitalStaging commented 10 years ago

Can this class not be extended to use threading?

shirioko commented 10 years ago

PHP can't use threading.

8DigitalStaging commented 10 years ago

trying to use pthread

8DigitalStaging commented 10 years ago

How else could you do it without using threading? Your example in .net uses threads

mgp25 commented 10 years ago

PHP != C#

shirioko commented 10 years ago

Just like how any processor does it, using interrupts based on timers

$interval = 60;//seconds
$start = time();
while(true)
{
    $wa->pollMessage();
    $now = time();
    if($now > ($start + $interval))
    {
        //tick
        $wa->sendGetPrivacyBlockedList();
        $start = time();//reset timer
    }
}

Also, PHP < C#

8DigitalStaging commented 10 years ago

Thanks for all your help. Much appreciated! Now I get this error notice: fwrite(): send of 12 bytes failed with errno=32 And the script stops. Could it be my php max exec time timing out? Not sure why this is. I have tried using sendPresence to get rid of the stream:error error, tried to use sendPong but still its stopping with the notice above. Any Ideas?

8DigitalStaging commented 10 years ago

Never mind. Figured it out. Sorted. Thanks.