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

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

问题描述

我可以按照以下代码手动发送通知.

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 集成.但是文件太多了.就我而言,只有一个文件有用.

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

现在我想通过我的 API 在 iOS 中发生某些事件时运行这个 php 脚本.所以我可以在某个函数下编写这段代码,并在发生某些事件时调用该函数.那么最好的方法是什么?以及如何实现每 5 分钟运行一次的通知 cron?

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?

任何帮助将不胜感激.

推荐答案

/etc/cron.d/

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

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

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