我知道这个问题已被多次询问,但我正在寻找另一个解决我的问题的答案。PHP:504网关超时错误?
基本上,我有超过10000条记录iPhone的设备ID的在它推送通知MySQL数据库。
现在,我需要运行将连接到苹果服务器APNS在我的MYSQL数据库发送推送通知这些10000条记录的PHP文件。
当我运行我的PHP页面,过了一会儿,我得到我的研究,我跨越了几个解决方案,来了一个超时错误...
但大多数需要编辑在etc文件夹的一些东西在服务器上。
我的问题是:
有没有办法选择让说,从MySQL数据库30条记录,然后停止,然后选择另外的30,然后停下来,然后又30等依此类推,直到该谁记录已经发送了PN的?
这是我当前的代码:
$message = "Welcome";
$sqld = "SELECT * FROM pushUsers ORDER BY id DESC";
$queryd = mysqli_query($db_conx, $sqld);
$productCountd = mysqli_num_rows($queryd); // count the output amount
if ($productCountd > 0) {
//while($rowd = mysqli_fetch_array($queryd, MYSQLI_ASSOC)){
while($rowd = mysqli_fetch_assoc($queryd)){
$deviceID = $rowd["deviceNo"];
$deviceType = $rowd["deviceType"];
if($deviceType == 'iPhone' || $deviceType == 'iPad'){
///////////////SEND PUSH NOTU8FOCATION FOR iOS//////////////////////
// Put your device token here (without spaces):
$deviceToken = ''. $deviceID.'';
// Put your private key's passphrase here:
$passphrase = '123456';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apple_push_notification_production.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
//****IMPORTANT**** LIVE APNS URL:
//ssl://gateway.sandbox.push.apple.com:2195
$fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => ''.$message.'',
'sound' => 'default',
'link_url' => 'http://xxxx.xom',
'category' => 'APP',
'badge' => '1',
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
///////////////END SEND PUSH NOTU8FOCATION FOR iOS//////////////////////
}
}
} else {
}
任何帮助,将不胜感激。
在此先感谢。
的可能的复制[分页使用MySQL LIMIT,OFFSET(https://stackoverflow.com/questions/20364349/pagination-using-mysql-limit-offset) – bishop
你可以存储在一个文件中当前数据库的位置 –
@bishop,分页?!? –