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

Why Sending & Receiving take too much time #876

Closed
vibhoo opened this issue Aug 11, 2014 · 30 comments
Closed

Why Sending & Receiving take too much time #876

vibhoo opened this issue Aug 11, 2014 · 30 comments

Comments

@vibhoo
Copy link

vibhoo commented Aug 11, 2014

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 ?

@mgp25
Copy link
Contributor

mgp25 commented Aug 11, 2014

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

@recoverjp
Copy link

The delay is the connection with the server whatsapp, not the sending.

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

@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

@recoverjp
Copy link

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.

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

@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 ?

@ardianys
Copy link
Contributor

I guest you also include connection and authentication time,
I'm using whatsapi and I send / get messages just in seconds.
You should keep connection to whatsapp server live.

@recoverjp
Copy link

If the connection is kept alive, sending and receiving is instantaneous. But I'm considering it need make a new connection to send something.

@recoverjp
Copy link

It is not harmful to the server leave a running script 24 hours?

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

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 ?

@ardianys
Copy link
Contributor

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.

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

How to keep connection alive? can you guys help me ?any script or code will help as I am new to PHP

@ardianys
Copy link
Contributor

@vibhoo yes, the account status will be set to 'online'

@recoverjp
Copy link

@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.

@ardianys
Copy link
Contributor

just simple loop like this

                $wa = new WhatsProt($sender, $imei, $nickname, $debug);
            $wa->connect();
            $wa->loginWithPassword($password);
        while (TRUE) {
          $wa->pollMessage();
          echo '.';
          sleep(2);
        }

@recoverjp
Copy link

But it can run on a server 24 hours? Does not weigh to the server? And how to stop this script after it started?

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

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?

@ardianys
Copy link
Contributor

You should not sending image to user in script that they execute, ( in function that handle form request)
But You can put this image request in queue. Than you can modify the script :

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.
You also should give it some delay.

@recoverjp
Copy link

@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.

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

@recoverjp I have no problem If you can send, its upto you I have no problem in understanding the code

@ardianys
Copy link
Contributor

To get group name, you should listen when you added to group participants.
Currently I'm working to complete this line

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;

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

@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

@ardianys
Copy link
Contributor

Of course, the source code is not yet finished. You should complete it first.

@ardianys
Copy link
Contributor

Actually whatsapi already have function to get group subject,
But whatsapp change their format

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'm sure @shirioko already made a lot of work on this.

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

I checked it out but don't know why I am not getting the result? Surely when you implement just let me know

@ardianys
Copy link
Contributor

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;
  }

@mgp25
Copy link
Contributor

mgp25 commented Aug 12, 2014

@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..

@ardianys
Copy link
Contributor

You just have to enable debugging in WhatsProt constructor. I just modifiying what already exist here. I'm not an expert.
Maybe it's because php itself, compared with python and .net
Previously I tried yowsup, but they are using old auth that don't have contact sync feature.

@shirioko
Copy link
Contributor

I'll try using progressive reading instead of buffered reading, that should make it more efficient

@ardianys
Copy link
Contributor

👍

@vibhoo
Copy link
Author

vibhoo commented Aug 12, 2014

@shirioko 👍

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

No branches or pull requests

5 participants