venomous0x / WhatsAPI

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

API too slow? #749

Closed eliasjnior closed 10 years ago

eliasjnior commented 10 years ago

I'm testing this API to make some apps online, but when I try to send a message, for exemple, my php script run about 7s. I tried in 3 servers and had the same issue.

I was testing the Python API and its less then a second to send a message.

mgp25 commented 10 years ago

@eliasjnior It works perfectly for me. Test http://watools.es is a project based on WhatsAPI, and it sends messages instantly.

eliasjnior commented 10 years ago

After I send in your page, it loads in about 5s too.

mgp25 commented 10 years ago

@eliasjnior but the page itself (images, scripts...), but the message is sent at the moment, try a simple script, it will work :)

eliasjnior commented 10 years ago

But what is making this slow? Even after you have sent the message? Is something on your page or on the API? Here I realized the same thing: the message is sent, but then the page takes a while to load.

mgp25 commented 10 years ago

@eliasjnior did you try to run the script on the terminal?

php script.php

Yes, its because of my page (slow server, images, javascripts...)

eliasjnior commented 10 years ago

I'll try to do it later. Hope it works normal, because I was almost creating my program in Python (I gotta learn First) because PHP was slow. I'll test on a more powerful server from the command line.

eliasjnior commented 10 years ago

Here's what i got: PHP: http://pastebin.com/9b4mkyTz Screenshot: https://www.diigo.com/item/p/peccscezcbpqbqecszbeaaedpe Terminal: https://www.diigo.com/item/p/peccscezcbpqbqqprzbeaaedrc

So, the PHP in the page: 7s. PHP in terminal: 8s (rounded). The script is simple. Is that right?

eliasjnior commented 10 years ago

So, I think that the login is taking this time. I placed this code 44x:

$wa->sendMessage('557399722520','Testing:  '.rand(0,1000));

I got: Start: 1402933198 Finish: 1402933213 Total: 15

So, when I send this 44 messages, it takes about 7s, 0.16s each message. It's about 7s to login and 0,16s each message.

Is there any way to reduce this login time?

mgp25 commented 10 years ago

@eliasjnior i login in, and it takes me about a second.

Anyway, i dont support people who want to send massive messages:

Have a look to this EULA

eliasjnior commented 10 years ago

No problem. I don't want send multiple messages. I'm just testing the API because I want use it in WordPress. So, will be possible answer comments with WhatsApp, receive messages when someone comment publish... and other things. The bulk message that I tried right now was just to see what was causing the "slowness", and I found that was login.

mgp25 commented 10 years ago

@eliasjnior if you are using it for wordpress as a plugin then 7 seconds of delay is not a problem (just like a push notification).

Maybe you internet connection isnt fast enought and that why your slowness logging in

eliasjnior commented 10 years ago

This is just the login: http://pastebin.com/dKvYD9pi Start: 1402937031 Finish: 1402937040 Total: 9

My connection? I don't really think that is the problem: http://www.speedtest.net/my-result/3567031089

Can you test and look if this script takes the same time? If not, I will try with some hosting.

Edit: and yes, to my WP Plugin, no problem this 7s. But, if I can solve this, it will be better.

Edit 2: the same script running: http://site9.com.br/w/tests/whatsapp-test.php

Edit 3: So, I found what is taking so long here: function pollMessage. About 2-3s each call. I saw that in the doLogin it's called 2 or 3 times. Is that necessary, as I'm doing just login? Isn't better for me use this function in getMessages?

mgp25 commented 10 years ago

@eliasjnior I test the script with

microtime(true);

For being the most accurate with the time. It takes me 3.6283469200134 seconds. Its not a big delay, is not a problem though.

eliasjnior commented 10 years ago

Undestood. So, it's not a problem here. Thanks.