onlinecity / php-smpp

PHP 5 based SMPP client library
232 stars 160 forks source link

Send SMS fatal error - Could not read PDU body #48

Closed Sogl closed 9 years ago

Sogl commented 9 years ago

Hi!

I'm trying to use send SMS example but it don't work.

After setting all parameters I see these errors:

Notice: Use of undefined constant MSG_DONTWAIT - assumed 'MSG_DONTWAIT' in C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\sockettransport.class.php on line 327

Warning: socket_recv() expects parameter 4 to be long, string given in C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\sockettransport.class.php on line 327

Fatal error: Uncaught exception 'RuntimeException' with message 'Could not read PDU body' in C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\smppclient.class.php:711 Stack trace: #0 C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\smppclient.class.php(682): SmppClient->readPDU() #1 C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\smppclient.class.php(619): SmppClient->readPDU_resp(1, 2) #2 C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\smppclient.class.php(479): SmppClient->sendCommand(2, '7914759*****\x0079...') #3 C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\smppclient.class.php(134): SmppClient->_bind('7914759*****', '7914759*****', 2) #4 C:\OpenServer\domains\sms\sender.php(42): SmppClient->bindTransmitter('7914759*****', '7914759*****') #5 {main} thrown in C:\OpenServer\domains\sms\vendor\php-smpp\php-smpp\smppclient.class.php on line 711

What I'm doing wrong?

Sogl commented 9 years ago

Line 711 (I add var_dump after):

$body=$this->transport->readAll($length-16);
var_dump($length-16);
var_dump($body);

Result:

int(14)
NULL
cypres commented 9 years ago

Hi Sogl, as stated in the F.A.Q.. For Windows, you'll need the older windows compatible version, which does not use the socket extension. https://github.com/onlinecity/php-smpp/tree/windows-compatible

Sogl commented 9 years ago

Ok, but if I test same code on Limux Ubuntu Server 14.04 I got another error:

Fatal error: Uncaught exception 'SocketTransportException' with message 'Could not connect to any of the specified hosts' in /var/www/sms/vendor/php-smpp/php-smpp/sockettransport.class.php:262 Stack trace: #0 /var/www/sms/sender.php(55): SocketTransport->open() #1 {main} thrown in /var/www/sms/vendor/php-smpp/php-smpp/sockettransport.class.php on line 262

For test I install PEAR ping. Code:

    require_once "Net/Ping.php";
    $ping = Net_Ping::factory();
    if (PEAR::isError($ping)) {
        echo $ping->getMessage();
    } else {
        $ping->setArgs(array('count' => 4));
        var_dump($ping->ping('smpp.mcommunicator.ru'));
    }

And ping works fine!

cypres commented 9 years ago

That ping works does not mean that a firewall does not block TCP communication. Try opening a telnet session to the specific host and port number.

Sogl commented 9 years ago

Telnet to this host/port works fine, just tested.

($this->hosts) contain valid host and IP.

Sogl commented 9 years ago

Where can I see debug messages like that:

if ($this->debug) call_user_func($this->debugHandler, "Connecting to $ip:$port...");

Debug mode is ON.

cypres commented 9 years ago

'Could not connect to any of the specified hosts' is a clear indication of connection issues, so you need to work this out on your own.

Sogl commented 9 years ago

Line 249 in sockettransport.class.php causes the problem:

$r = @socket_connect($socket4, $ip, $port);

All variables are not empty, but $r is NULL.

Found the same: https://github.com/onlinecity/php-smpp/issues/35

janke184 commented 7 years ago

Dears, Could you solve it? I have the same problem.