无法通过Ozeki短信服务器使用PHP代码发送短信

时间:2015-05-17 13:10:30

标签: php ozeki

我试图通过Ozeki短信服务器使用PHP代码发送短信。我可以使用Ozeki提供的接口通过direclty正确发送短信。但是这段PHP代码并没有像我预期的那样做。我已连接到:127.0.0.1:9333(admin)

它显示了Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\...\sendsms.php on line 32
,其代码为$greeting = trim(fgets($ozekiSMSSocket,1000));
什么是错的?

这是代码:

<?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();
?>

这是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);
}
?>

1 个答案:

答案 0 :(得分:1)

超时的原因是,您尝试从套接字读取1000个字节,但服务器没有发送任何内容。

至于为什么&#34; Ozeki短信服务器&#34;没有发送任何东西,我不知道。但是,如果您确实应该在连接后立即收到问候消息,则应查看文档。通常,您希望客户端通过发送请求来启动通信。