Timeout with PHP's SendSMS Function

Timeout with PHP's SendSMS Function SearchSearch
Author Message
Chris Sammy
New member
Username: Csammy

Post Number: 12
Registered: 11-2010
Posted on Wednesday, March 16, 2011 - 07:38 am:   

Hello,

I'm using the PHP documentation for SendSMS() function unmodified from the example provided in the documentation. However, even when only sending one message to NowSMS, the PHP script has a timeout:

"Fatal error: Maximum execution time of 30 seconds exceeded"

Is there any reason this would be caused? I have installed WAMP on a windows machine and the PHP script sends a simple message to NowSMS.
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3009
Registered: 08-2008
Posted on Wednesday, March 16, 2011 - 12:44 pm:   

Hi Chris,

Does the message actually get sent?

I know there was a problem in our MMS PHP script that it specified HTTP/1.1, and recent versions of NowSMS support keep-alive sockets in the SMS gateway by default, so they expect HTTP/1.1 applications to support keep-alives, which leads to timeout errors unless you change the script to use HTTP/1.0.

I don't think any versions of our SMS PHP script used HTTP/1.1, however. But this is something to check.

If it's not that, then I'm puzzled. Does the message actually get sent, despite the timeout error?

--
Des
NowSMS Support
Chris Sammy
New member
Username: Csammy

Post Number: 13
Registered: 11-2010
Posted on Wednesday, March 16, 2011 - 06:24 pm:   

Hi Des,

I have corrected this issue but now I receive this message when I try to send out SMS messages:

ERROR - Error waiting for response from modem (2) -- GlobeTrotter Icon322 - Modem Interface

This makes it so the messages are sent out very slowly (1 per minute sometimes). I'm on the trial of NowSMS but it says 30messages/min.

Here's my INI:

[SMSGW]
Modem1=GlobeTrotter Icon322 - Modem Interface
WebAuth=No
WebMenu=Yes
WebPort=8800
SeparateUserQueues=Yes
ReceiveSMS=Yes
ReceiveMMS=No
ReceiveSMSCharset=utf-8
ConfigurationUpdateTriggerRestart=20110316121132
ReceiveSMSCommand1=* http://www.domain.com/sms_parser.php?addr=@@SENDER@@&message=@@FULLSMS@@ No 50****4243
[Modem - GlobeTrotter Icon322 - Modem Interface]
PhoneNumber=50****4243
ReceiveSMS=Yes
ReceiveMMS=No
ReceiveTo=ME
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3012
Registered: 08-2008
Posted on Wednesday, March 16, 2011 - 06:50 pm:   

Hi Chris,

From the SMSC list, select the modem and press the Properties button.

Try changing the "SMS Access" setting to GSM.

"ERROR - Error waiting for response from modem (2)" means that the modem is not acknowledging whether or not a message has been transmitted. NowSMS waits up to 2 minutes for this acknowledgment.

That is not a common problem on the ICON 322, so I am confused as to why this would be.

Aside from the "SMS Access" setting, the only other issue I can think of is if your GSM signal strength is very low. (Although I would expect an error to be returned by the modem before NowSMS times out.)

If you enable the SMSDEBUG.LOG (checkbox option on "Serial #" page), at startup, NowSMS sends the AT+CSQ command and records its response in the log. This command reports current GSM signal strength. The first number is the one that is important, and you generally want it to be in the 20's or 30's for a good connection.

--
Des
NowSMS Support
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3013
Registered: 08-2008
Posted on Wednesday, March 16, 2011 - 06:52 pm:   

Follow-up ... I just re-read your message, and want to make sure I understood it correctly.

Some messages are actually being sent out, right?

I'm assuming that this timeout error only occurs sometimes, and other times messages are being sent out.

If no messages are ever being sent out, then this becomes a different issue. The two suggestions above are still valid as a starting point. (Beyond that, you want to move the SIM from the modem to a phone and confirm it is still working.)

--
Des
NowSMS Support
Chris Sammy
New member
Username: Csammy

Post Number: 14
Registered: 11-2010
Posted on Wednesday, March 16, 2011 - 07:21 pm:   

Des - yes, certain messages do send, but at other times it displays the message that it's waiting for a response from the modem.

I've enabled the logs and I am testing again.
Chris Sammy
New member
Username: Csammy

Post Number: 15
Registered: 11-2010
Posted on Wednesday, March 16, 2011 - 07:26 pm:   

Des,

This cam from the SMSDEBUG.LOG

OK

13:20:08:546 [3] ThreadProcessModem: AT+CSQ
13:20:08:562 [3] ThreadProcessModem:
+CSQ: 20,0


Looks like the signal strength is sufficient, yes?
Chris Sammy
New member
Username: Csammy

Post Number: 16
Registered: 11-2010
Posted on Wednesday, March 16, 2011 - 07:46 pm:   

The error message for a particular message looks like this:

LastErrorInfo=ERROR - Modem Response (2): +CPMS: "SM",0,30,"SM",0,30,"SM",0,30 -- GlobeTrotter Icon322 - Modem Interface
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3014
Registered: 08-2008
Posted on Wednesday, March 16, 2011 - 08:13 pm:   


quote:

ERROR - Modem Response (2): +CPMS: "SM",0,30,"SM",0,30,"SM",0,30




Now that is very strange. That is a response from a completely different command.

Can I see a full SMSDEBUG.LOG that shows some message sending attempts? (If you don't want to post it here, e-mail to nowsms@nowsms.com and put "Attention: Des" in the subject line. Post a follow-up here to tell me to go look for the log.)

Also, please note what version of NowSMS you are running.

And if you have a different USB port that you can try, do that as well, as it almost looks like there is some sort of USB synchronisation problem occurring.

--
Des
NowSMS Support
Chris Sammy
New member
Username: Csammy

Post Number: 17
Registered: 11-2010
Posted on Wednesday, March 16, 2011 - 08:33 pm:   

Des,

I have sent you that email. Version 2011.11.04.

I tried switching the USB, no such luck. It seems to not have this issue if the queue is rather small but once it gets high (over 10 or so) it has difficulty. Is it trying to make to many connections at once?
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3015
Registered: 08-2008
Posted on Wednesday, March 16, 2011 - 10:20 pm:   

Chris,

There weren't any message sending problems in that particular log, but nonetheless it was interesting.

There are repeated errors when NowSMS tries to poll device memory for received messages. The modem seems to be indicating that there is no device memory message storage. I've run some tests with NowSMS on the same model modem here, and I don't see those errors.

These errors are not necessarily a problem, they just suggest that the modem might have a memory problem.

I would suggest going into properties of the modem on the SMSC list, and changing "SMS Message Storage" to SIM.

I'm not sure if that will fix any operational problems. But I would be interested in taking a look at another log after you do this, if you see a large number of these "timeout (2)" errors.

Note that it is not unusual to see these errors occasionally. If a message comes in while a modem is in a process of sending an outbound message, the modem may abort the sending process unexpectedly. It should return an error, and the message will be retried.

At this point, I don't have too much to go on other than a strange error in the log about device memory storage, so try changing that setting, and if necessary send me another debug log to look over.

--
Des
NowSMS Support
Chris Sammy
New member
Username: Csammy

Post Number: 18
Registered: 11-2010
Posted on Thursday, March 17, 2011 - 04:10 pm:   

> > > > Hi Des, >

No, the message is not sent. and it is using HTTP/1.0. Please find the function I'm using below:

function SendSMS ($host, $port, $username, $password, $phoneNoRecip, $msgText) {

$fp =3D fsockopen($host, $port, $errno, $errstr); if (!$fp) { echo "errno: $errno ::"; echo "errstr: $errstr::"; return $result; }

fwrite($fp, "GET /?Phone=3D" . rawurlencode($phoneNoRecip) . "&Text=3D"= . rawurlencode($msgText) . " HTTP/1.0::"); if ($username !=3D "") { $auth =3D $username . ":" . $password; $auth =3D base64_encode($auth); fwrite($fp, "Authorization: Basic " . $auth . "::"); } fwrite($fp, "::");

$res =3D "";

while(!feof($fp)) { $res .=3D fread($fp,1); } fclose($fp);

return $res;

}

Are there any other ways to send a message to NowSMS using PHP?



> >
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 3020
Registered: 08-2008
Posted on Thursday, March 17, 2011 - 06:52 pm:   

Hi Chris,

Your message came through pretty garbled. I wish the e-mail interface for this discussion board was a bit more robust.

I'll take your word that it is our standard code, as published here:

http://www.nowsms.com/download/sendsms-php.txt

If the message isn't getting sent at all, it sounds like something is going wrong with the request.

The "\n" references in the PHP request are important. There needs to be one after each line of the HTTP header, and then one by itself to signify a blank line in the HTTP header.

If one of these is missing, the server won't see the end of the HTTP request, and the PHP script will loop until the server times out the connection.

So I guess the question is ... when the script fails ... is the request ever making it to the NowSMS server? Since we were looking at the SMSDEBUG.LOG earlier ... Do you see the TCP connection in the SMSDEBUG.LOG? If so, what does NowSMS log about it?

Is the PHP script running on the same server, or different?

If different servers, then by any chance are you sending MMS messages when the problem occurs? There can be a complicated issue if your LAN IP address range conflicts with the dynamic IP addresses assigned by your provider when making a data connection for sending/receiving MMS.

--
Des
NowSMS Support