php - 发送批量短信中途停止

标签 php mysql sms sms-gateway bulksms

伙计们,我在以下代码中遇到问题。我需要向 24,000 个手机号码发送批量短信。但如果我在发送 150 个号码后发送它,它会显示内部服务器错误并停止发送其他后续号码。请仔细阅读下面给出的代码并回复对我真正有帮助的积极代码。

<?php
//Code using fopen
//Change your configurations here.
//---------------------------------
$username = "username";
$api_password = "api_password";
$sender = "sender";
$domain = "domain";
$priority = "1";// 1-Normal,2-Priority,3-Marketing
$method = "POST";

//---------------------------------
for ($i = 0; $i < $var; $i++) {
    if (isset($_REQUEST['send'])) {

        $mobile = $explode_num[$i];
        $lenthof_number = strlen($mobile);
        if ($lenthof_number >= 10) {
            $message = $_REQUEST['message'];

            $username = urlencode($username);
            $password = urlencode($api_password);
            $sender = urlencode($sender);
            $message = urlencode($message);

            $parameters = "username=$username&api_password=$api_password&sender=$sender&to=$mobile&message=$message&priority=$priority";


            if ($method == "POST") {
                $opts = array(
                    'http' => array(
                        'method' => "$method",
                        'content' => "$parameters",
                        'header' => "Accept-language: en\r\n" .
                            "Cookie: foo=bar\r\n"
                    )
                );

                $context = stream_context_create($opts);

                $fp = fopen("http://$domain/pushsms.php", "r", false, $context);
            } else {
                $fp = fopen("http://$domain/pushsms.php?$parameters", "r");
            }

            $response = stream_get_contents($fp);
            fpassthru($fp);
            fclose($fp);


            if ($response == "")
                echo "Process Failed, Please check domain, username and password.";
            else
                echo "$response";


        }//third if
    }//second if


}//first if
}//main for

?>

最佳答案

您的页面可能超出了最大执行时间。将以下代码放在页面顶部并尝试:

ini_set("memory_limit","128M"); 
//ini_set("memory_limit","256M"); 
//this sets it unlimited
ini_set("max_execution_time",0); 

关于php - 发送批量短信中途停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20043572/

相关文章:

javascript - 如何在一个固定根上设置 Service Worker

php - 优化Zend框架路由

php - 使用 Laravel 在 Docker Mysql 上连接被拒绝

android - 在 list 中声明时,RECEIVE_SMS 的广播接收器不起作用(静态)

java - MTN 移动货币整合

php - iframe 更改 src 后调整主体高度

php - 插入多个数据

php - 需要将 MySQL 记录转换为 JSON 树

MYSQL - GROUP_CONCAT 和 FIND_IN_SET 是混合值/顺序吗?

java - 如何将我的位置(经度和纬度)作为回复短信发送给其他人?