venomous0x / WhatsAPI

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

sendMessageImage and "Socket closed" Exception #1018

Open DSC0088 opened 9 years ago

DSC0088 commented 9 years ago

After sending a large image, exception "Socket closed" throws. Here in the examples is recommended to periodically cause $w->sendPresence(); $w->pollMessage(); the connection is not broken. But how to do it while sending image? The image is large (4.5 MB), and sending takes 2-3 minutes. What the timeout is on the whatsapp server? Or the reason in other? In what cases, an exception "Socket closed" occurs? In what direction to look?

Here is the script. The result of the script - nothing comes to the smartphone. The script ends with exception "Socket closed".


require_once('/../WhatsAPI/src/whatsprot.class.php');

set_time_limit(0);
ini_set('max_execution_time',0);
ini_set("default_socket_timeout","300");

$w = new WhatsProt('<fromnumber>', '012345678901234', 'Nick1', true);

$w->connect();
$w->loginWithPassword('<frompass>');
$w->sendMessageImage('<tonumber>', "C:\\bigimage.jpg");
$w->sendMessage('<tonumber>', "Message1");

for ($i=1; $i<=10; $i++){
    $w->sendPresence();
    $w->pollMessage();
    sleep(10);
}
eliasjnior commented 9 years ago

It's because in 300 seconds, or 3 minutes, I don't know, the server close connection. It's better if you convert your image first, don't you think? Use php-gd.