MerNion Posted September 28, 2010 Share Posted September 28, 2010 Hey all, I have a simple php script that whenever it is run (it is called x times per day from crontab) it sends out an sms to 10 people. Unfortunatelly the cell carrier has put a "delay" threshold of 30 seconds between sms that you can send in order to prevent sms spamming. The problem is that my script had a foreach loop that it just send out the sms to everyone so it took around 0.5-1 second for each sms.. Way to low for the 30 seconds that now are enforced. Do you have any ideas of what i can do to "force" my script to obey that 30 second delay between each sms? I thought of putting a cron job every 1 minute and send one by one the sms but wouldn't that be a problem to the server to have to execute 1440 times per day a script? I also thought of using some sleep function but i don't know if that would result in finally the script to output a success result after 10*30=300seconds(5mins).. Any ideas are appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/ Share on other sites More sharing options...
micah1701 Posted September 28, 2010 Share Posted September 28, 2010 add sleep(30); at the end of the loop before it restarts to send the next message. its running as a cron you said, so its not like you're waiting for your browser to load for 5 minutes to see a success result. Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116826 Share on other sites More sharing options...
fortnox007 Posted September 28, 2010 Share Posted September 28, 2010 Maybe offtopic, but how do you even send an sms using php? If anyone knows i really love to hear that : ) Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116827 Share on other sites More sharing options...
MerNion Posted September 28, 2010 Author Share Posted September 28, 2010 Thx micah1701. I will try that and come back with the result. @fortnox007. You need either to find a gateway service or use your own cellphone through the serial port... The easier is the first and you pay per sms you send.. Try googling "SMS gateway". You can use several ways to actually send it from the php to the server. Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116843 Share on other sites More sharing options...
Rifts Posted September 28, 2010 Share Posted September 28, 2010 this is easiest way to send sms THE FORM <form id="sms" name="sms" method="post" action="scripts/send_sms.php"> <table width="400"> <tr> <td align="right" valign="top">From:</td> <td align="left"><input name="from" type="text" id="from" size="30" /></td> </tr> <tr> <td align="right" valign="top">To:</td> <td align="left"><input name="to" type="text" id="to" size="30" /></td> </tr> <tr> <td align="right" valign="top">Carrier:</td> <td align="left"><select name="carrier" id="carrier"> <option value="verizon">Verizon</option> <option value="tmobile">T-Mobile</option> <option value="sprint">Sprint</option> <option value="att">AT&T</option> <option value="virgin">Virgin Mobile</option> </select></td> </tr> <tr> <td align="right" valign="top">Message:</td> <td align="left"><textarea name="message" cols="40" rows="5" id="message"></textarea></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form> the EXE script: <?php $from = $_POST['from']; $to = $_POST['to']; $carrier = $_POST['carrier']; $message = stripslashes($_POST['message']); if ((empty($from)) || (empty($to)) || (empty($message))) { header ("Location: sms_error.php"); } else if ($carrier == "verizon") { $formatted_number = $to."@vtext.com"; mail("$formatted_number", "SMS", "$message"); // Currently, the subject is set to "SMS". Feel free to change this. header ("Location: sms_success.php"); } else if ($carrier == "tmobile") { $formatted_number = $to."@tomomail.net"; mail("$formatted_number", "SMS", "$message"); header ("Location: sms_success.php"); } else if ($carrier == "sprint") { $formatted_number = $to."@messaging.sprintpcs.com"; mail("$formatted_number", "SMS", "$message"); header ("Location: sms_success.php"); } else if ($carrier == "att") { $formatted_number = $to."@txt.att.net"; mail("$formatted_number", "SMS", "$message"); header ("Location: sms_success.php"); } else if ($carrier == "virgin") { $formatted_number = $to."@vmobl.com"; mail("$formatted_number", "SMS", "$message"); header ("Location: sms_success.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116847 Share on other sites More sharing options...
MerNion Posted September 28, 2010 Author Share Posted September 28, 2010 What about Vodafone? This is very "carrier-specific" and only to US carriers as I see... US is not the world... A sms gateway will send to whichever cell phone, wherever in the world... Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116849 Share on other sites More sharing options...
Rifts Posted September 28, 2010 Share Posted September 28, 2010 go here for the list for THE WORLD http://www.mutube.com/projects/open-email-to-sms/gateway-list/ if you want to add a "not sure" option to the pulldown menu), add @teleflip.com as the suffix Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116887 Share on other sites More sharing options...
MerNion Posted September 28, 2010 Author Share Posted September 28, 2010 Yeah ok, just don't continue off topic in my thread please... And just for the record these are just 17 out of the 195 Back to my original post subject: I did put the sleep(30) there but it "pauses" the output of the page as well on each turn in the foreach statement.. $users = ("bob"=>"94124912421", "lol"=>"4134241242", "paul"=>"41240241"); foreach ($users as $user=>$cell) { echo "Sending message to user " . $user . "<br>"; send($cell,"test"); sleep(30); } What happens is that it looks like it is loading for 3*30=90seconds and then it outputs all together (with pages fully loaded now) Sending message to user bob Sending message to user lol Sending message to user paul Isn't there a way for this not to happen? Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116894 Share on other sites More sharing options...
PFMaBiSmAd Posted September 28, 2010 Share Posted September 28, 2010 If you append the date/time to each of those status messages, you will be able to see when each one was processed. Web servers are not designed to output content to the browser incrementally. Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116895 Share on other sites More sharing options...
MerNion Posted September 28, 2010 Author Share Posted September 28, 2010 Thanks! I understand that each send command was executed with 30 second interval and that is ok as for my initial problem of sending them with that delay... The second part though (as to how not to have the page looking of doing nothing for x*30 seconds), is the most challenging one.. Any ideas for that? Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116898 Share on other sites More sharing options...
chmpdog Posted September 28, 2010 Share Posted September 28, 2010 maybe try executing an ajax script so the page can load, but then send the sms Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116902 Share on other sites More sharing options...
MerNion Posted September 28, 2010 Author Share Posted September 28, 2010 The thing is that this page is both accessed from the users and from crontab... when the user access it i can have the ajax send the SMSs but when its run from the crontab i guess it will just take it a little more time to complete the run... (i have to take into account the max execution time though, right?) Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116905 Share on other sites More sharing options...
fortnox007 Posted September 28, 2010 Share Posted September 28, 2010 thanks micah1701. I will try that and come back with the result. @fortnox007. You need either to find a gateway service or use your own cellphone through the serial port... The easier is the first and you pay per sms you send.. Try googling "SMS gateway". You can use several ways to actually send it from the php to the server. Thx for you wicked answer I found gateway, but nice to know you can do it via a cell phone too. have a nice eve! Quote Link to comment https://forums.phpfreaks.com/topic/214636-delaying-sms-sending-from-php-script/#findComment-1116909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.