Skip to content

Instantly share code, notes, and snippets.

@antonraharja
Last active December 8, 2023 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonraharja/849d417f6e06cc6c90bc680f2e73b20d to your computer and use it in GitHub Desktop.
Save antonraharja/849d417f6e06cc6c90bc680f2e73b20d to your computer and use it in GitHub Desktop.
Generate test SMS
<?php
/**
* Copy this file to playSMS web path and run from shell
*/
include 'init.php';
include $core_config['apps_path']['libs'] . '/function.php';
ob_end_clean();
$sender_username = 'user1'; // make sure user1 is exists
$from = '1234'; // can be any sender ID
$to = []; // this will be filled below, default is to 1k numbers
$messages = []; // this also will be filled below, default is for 10 type of SMS message
// send to 1k numbers
// make sure to setup route for 1555 to use gateway dev
for ($i = 0; $i < 1000; $i++) {
$to[] = 15553000001 + $i;
}
// send 10 types of SMS message to each 1k numbers above
for ($i = 0; $i < 100; $i++) {
$messages[] = 'With $' . ($i + 1) . ' you can buy item #' . str_shuffle(uniqid()) . ' for a discount!';
}
// LETS START
$total_duration = 0;
$start = time();
$i = 0;
foreach ( $messages as $message ) {
$i++;
echo '#' . $i . '. c:' . count($to) . ' m:' . $message . PHP_EOL;
$time_start = time();
echo " Start: " . date('Y-m-d H:i:s', $time_start) . PHP_EOL;
list($status, $sms_to, $smslog_id, $queue, $counts, $error_strings) = sendsms($sender_username, $to, $message, 'text', 0, '', true, '', $from, '');
$time_stop = time();
echo " Stop: " . date('Y-m-d H:i:s', $time_stop) . PHP_EOL;
$duration = $time_stop - $time_start;
echo " Duration: " . date('i:s', $duration) . PHP_EOL;
$total_duration += $duration;
}
$stop = time();
// DONE, NOW COUNTING TIME
echo PHP_EOL;
echo "First start: " . date('H:i:s', $start) . PHP_EOL;
echo "Last stop: " . date('H:i:s', $stop) . PHP_EOL;
echo "Total SMS: " . count($to) * count($messages) . PHP_EOL;
if ($total_duration > 3600) {
$total_duration_formatted = gmdate('H:i:s', $total_duration);
} else {
$total_duration_formatted = gmdate('i:s', $total_duration);
}
echo "Total duration: " . $total_duration_formatted . PHP_EOL;
// ALL DONE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment