1

I'm trying to send an sms using PHP code through Ozeki sms server. I can properly send an sms by direclty using the interface provided by Ozeki. But this piece of php code doesn't do the same thing as I expected. I have connected to : 127.0.0.1:9333(admin).

It shows
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\...\sendsms.php on line 32
which has the code $greeting = trim(fgets($ozekiSMSSocket,1000));
What will be the wrong?

This is the code:

<?php 
include("sendsms.php");
$credits = sms_connect('127.0.0.1','9333','admin'); 

if ($credits>1) {
echo "Sending messages...<br>";
sms_send('+36203105366','Send SMS messages from a PHP client!');
}

echo "Receiving messages...<br>";
$inbox = sms_receive();
echo "$inbox";

sms_disconnect();
?>

This is the code in sendsms.php

<?php
$ozekiSMSSocket = '';
$ozekiSMSCredit = 0;
function sms_connect($serverIP,$serverPort,$account) { 
global $ozekiSMSSocket;
global $ozekiSMSCredit;
$ret = true;
$ozekiSMSSocket = fsockopen($serverIP, $serverPort, $errno, $errstr, "60"); 

if ($errno) {
    echo $errstr;
    $ozekiSMSCredit = 0;
}

//$greeting = fgets($ozekiSMSSocket,1000);

$greeting = trim(fgets($ozekiSMSSocket,1000));
$randomstring = trim(fgets($ozekiSMSSocket,1000));

if (strlen($randomstring)) {
    $reply = md5($randomstring.$account).chr(13).chr(10);
    fputs($ozekiSMSSocket,$reply);
    $ozekiSMSCredit = trim(fgets($ozekiSMSSocket,1000));
}
return $ozekiSMSCredit;
}

function sms_send($msisdn,$msg) {
global $ozekiSMSSocket;
global $ozekiSMSCredit;
if ((isset($ozekiSMSSocket)) && ($ozekiSMSCredit>0)) {
    $msg=$msisdn.' '.$msg.chr(13).chr(10);
    fputs($ozekiSMSSocket,$msg);
} else {
    $ozekiSMSCredit = 0;
}
return $ozekiSMSCredit;
}

function sms_receive() {
global $ozekiSMSSocket;
$received = '';
if (isset($ozekiSMSSocket)) {
    $msg='OZEKI_INBOX'.chr(13).chr(10).'GET'.chr(13).chr(10);
    fputs($ozekiSMSSocket,$msg);
    $count = trim(fgets($ozekiSMSSocket,1000));
    for ($x=0;$x<$count;$x++) {
        $line = fgets($ozekiSMSSocket,1000);
        $received .= trim($line).chr(13).chr(10);
    }
}
return $received;
}

function sms_disconnect() {
global $ozekiSMSSocket;
if (isSet($ozekiSMSSocket)) fclose($ozekiSMSSocket);
}
?>
PrazSam
  • 1,166
  • 2
  • 12
  • 20

1 Answers1

1

The reason for the timeout is, that you're trying to read 1000 bytes from the socket, but the server isn't sending anything.

As to why the "Ozeki sms server" isn't sending anything, I don't know. But you should check the documentation if you really should expect a greeting message right after connecting. Normally you would expect the client to initiate communication by sending a request.

Beat
  • 1,337
  • 15
  • 30