-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Why Sending & Receiving take too much time #876
Comments
Try the example scripts in the test and examples folder. And check if takes the same time to send/receive. It takes 1 sec for me sending message using php |
The delay is the connection with the server whatsapp, not the sending. |
@recoverjp how can you be so sure about that? Because when we send messages form the mobile app(whatspp in mobile devices),the messages get delivered/sent and can be received within a fractions of seconds. So what's causing the delay? I don't think that connection to whatsapp server taking time |
Because if I run a script with only the connection with whatsapp, it takes on average 10 seconds. If I run a script with the connection and sending a message, it takes on average 10 or 11 seconds. But if the problem is not that and you find out, please share with me, because here also delay. |
@recoverjp no I didn't figure out what's exact the problem is but I think loginWithPassword()is taking time, & how did you run a script to test connection with the whatsapp? can you please share your script ? so that I can also test it ? |
I guest you also include connection and authentication time, |
If the connection is kept alive, sending and receiving is instantaneous. But I'm considering it need make a new connection to send something. |
It is not harmful to the server leave a running script 24 hours? |
Yeah to send Message we need to make the new connection, & if continue keeping the connection open then every time user will be shown as online ? |
I pull message from wa server one by one. And give some delay (2 seconds) after pollMessage(). I have run this on my prod server for some days. And everything is ok. |
How to keep connection alive? can you guys help me ?any script or code will help as I am new to PHP |
@vibhoo yes, the account status will be set to 'online' |
@ardianys, can you explain for us how you do it? I developed a site that users can request images. To send these images, each submission will be a new connection. And each connection takes around 10 seconds. |
just simple loop like this $wa = new WhatsProt($sender, $imei, $nickname, $debug);
$wa->connect();
$wa->loginWithPassword($password);
while (TRUE) {
$wa->pollMessage();
echo '.';
sleep(2);
} |
But it can run on a server 24 hours? Does not weigh to the server? And how to stop this script after it started? |
Any other way ? to speed up the things? or this is the only procedure by keeping the connection alive? & one more thing I nwould like to ask how to get the name of any group? |
You should not sending image to user in script that they execute, ( in function that handle form request) while (TRUE) {
$wa->pollMessage();
echo '.';
$queue = get one from queues
$wa->sendMessageImage($queue->to, $queue->filepath)
sleep(2);
} You should keep it live, You also make server busy if every 10 / 20 s you continuously sign in. You can stop it, make it offline, for example after some hours if there are no activities. |
@vibhoo I do not send to you my code because I'm using it in a framework, cakephp, then it gets tricky. But I did not change the shape of the api. I think this time connecting with whatsapp is equal for all. The @mgp25 said that it is fast because it must keep the connection alive as @ardianys is talking. |
@recoverjp I have no problem If you can send, its upto you I have no problem in understanding the code |
To get group name, you should listen when you added to group participants. https://github.com/venomous0x/WhatsAPI/blob/master/src/whatsprot.class.php#L2363 case "subject":
// rx <notification from="6285643077444-1407815451@g.us" id="894086480" participant="6285643077444@s.whatsapp.net" type="subject" t="1407815452" notify="Admin display name">
// rx <body>group name</body>
// rx </notification>
//TODO
break; |
@ardianys I tried this, but not happening Infact I am able to get the groupId and Messages of that particular group but not the group 'Subject' and 'Participants', I created a group using whatsapp on mobile, and added that no. or user to the group , When I am running script getting the message and groupId not the subject |
Of course, the source code is not yet finished. You should complete it first. |
Actually whatsapi already have function to get group subject, Previously the code to fire this event is like this if ($node->getAttribute('type') == "subject") {
print_r($node);
$reset_from = explode('@', $node->getAttribute('from'));
$reset_author = explode('@',$node->getAttribute('author'));
$this->eventManager()->fireGetGroupsSubject(
$this->phoneNumber,
reset($reset_from),
$node->getAttribute('t'),
reset($reset_author),
reset($reset_author),
$node->getChild(0)->getAttribute('name'),
$node->getChild(2)->getData()
);
} I'll try to move it on new place to make it work. |
I checked it out but don't know why I am not getting the result? Surely when you implement just let me know |
You can see the diff from my pull #879 And you can listen when the group name change with function onGetGroupsSubject($phone, $gId, $time, $author, $participant, $name, $subject){
echo $phone.', '.$gId.', '.$time.', '.$author.', '.$participant.', '.$name.', '.$subject;
} |
@ardianys i found a way i can see how the message nodes, iq ... are. Im also trying to complete the code when i have info enought ill send to you. And yes. Keep it alive so it goed faster, also what i did is a tweak that uses apple push notification to connect my script (im using the same wa passwd i have in my phone). The WhatsAPI code needs to be improved and maybe speeded up we will work on that, meanwhile yowsup and WhatsApiNet are faster if you want to try with them.. |
You just have to enable debugging in WhatsProt constructor. I just modifiying what already exist here. I'm not an expert. |
I'll try using progressive reading instead of buffered reading, that should make it more efficient |
👍 |
Hi! I have one question
I tried to send the message it's taking too much time around 16sec. & similarly for the receive message also it's taking time.
Internet connection is fine then why it's taking time ? anyone can help me in reducing time ?
The text was updated successfully, but these errors were encountered: