我正在尝试通过 Ozeki 短信服务器使用 PHP 代码发送短信。我可以使用 Ozeki 提供的接口直接发送短信。但是这段 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);
}
?>