sendBulkPush.php
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<? include $_SERVER["DOCUMENT_ROOT"] . "/common/classes/ApiProcess.php" ?>
<?
$obj = new ApiProcess($_REQUEST);
$pushTargetList = $obj->getBulkPushData($_REQUEST["push_code"]);
$push_msg = $_REQUEST["push_msg"];
$push_type = $_REQUEST["push_type"];
$push_no = $_REQUEST["push_no"];
$push_send_size = 10000;
$paramsArr = Array();
for($i=0; $i<(floor(sizeof($pushTargetList) / $push_send_size) + 1); $i++)
{
$paramsArr[$i] = "push_msg={$push_msg}&push_type={$push_type}&push_no={$push_no}";
}
for ($i=0; $i<sizeof($pushTargetList); $i++)
{
$targetData = Array(
"registration_key" => $pushTargetList[$i]["registration_key"],
"device_type_id" => $pushTargetList[$i]["device_type_id"],
"app_type" => $pushTargetList[$i]["app_type"]
);
$paramsStr = urlencode(json_encode($targetData));
$paramsArr[floor($i/$push_send_size)] .= "&targetList[]={$paramsStr}";
}
try {
$mh = curl_multi_init();
$chArr = Array();
for($i=0; $i<sizeof($paramsArr); $i++)
{
$chArr[$i] = curl_init();
curl_setopt($chArr[$i], CURLOPT_URL, "{$obj->con_domain}/action_front.php?cmd=ApiProcess.sendBulkPush");
curl_setopt($chArr[$i], CURLOPT_POST, true);
curl_setopt($chArr[$i], CURLOPT_POSTFIELDS, $paramsArr[$i]);
curl_multi_add_handle($mh, $chArr[$i]);
}
$active = null;
//execute the handles
do
{
$mrc = curl_multi_exec($mh, $active);
}
while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK)
{
if (curl_multi_select($mh) != -1)
{
do
{
$mrc = curl_multi_exec($mh, $active);
}
while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
//close the handles
for ($i=0; $i < sizeof($chArr); $i++)
{
// echo curl_multi_getcontent($chArr[$i]);
curl_multi_remove_handle($mh, $chArr[$i]);
}
curl_multi_close($mh);
}
catch (Exception $e)
{
curl_multi_close($mh);
echo $e->getTrace();
}
?>