在PHP中的cron通知的iPhone应用程序 [英] Notification cron in PHP for iphone Application

查看:144
本文介绍了在PHP中的cron通知的iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以手动发送通知如下code。

I can send notification manually as following code.

<?php

// Device token:
$deviceToken = 'xxxxxx';

$passphrase = 'xxxxx';
$badge = 1;

// Displays alert message here:
$message = 'Match Found!';


$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert',      '/Users/Documents/iOS_Application_Developement/new/APNSPHP/ApnsPHP-master/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client('ssl://gateway.sandbox.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,
'badge' => $badge,
'sound' => 'default'
);


// 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);

?>

我也有一个APNS PHP integration.but在有这么多files.For我的目的只有一个文件是很有用的。

I also had a APNS PHP integration.but in that there are so many files.For my purpose only one file is useful.

现在我要运行这个PHP脚本时一定发生在我的API发生在iOS版。所以,我可以写在某些功能这code和调用函数时一定发生发生。那么什么是做到这一点的最好方法是什么?我如何能实现运行cron的通知,每5分钟后?

Now i want to run this php script when certain occurrence take place in iOS through my API. So i can write this code under some function and call that function when certain occurrence take place. So what is the best way to do it? and how can i achieve notification cron that run after every 5 minutes?

任何帮助将AP preciated。

Any help will be appreciated.

推荐答案

创建 /etc/cron.d中/

 */5 * * * * root cd /path_to_your_script/ && php your_script.php >> /var/some.log &2>&1

这篇关于在PHP中的cron通知的iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆