Easy APNS Apple Push Notification Service using PHP & MySQL

Cron Job

Before you get started: You can download this source code here.

The easiest way to get your push notifications out in a timely manner is to schedule a frequent cron job. We suggest setting your cron job to run every minute, but of course you can do whatever you want ;)

Here are some different ways you can run your cron jobs. Before we start, make sure you know where the path to the apns.php file is you created using the tutorials from our PHP Source page. The paths we will use are merely examples, so make sure to change the paths to reflect your actual absolute paths.

STEP 1: Open a Terminal Window

Once you have opened a terminal window, type in the following...

crontab -e

STEP 2: Add a cron job

At the end of the file paste one of the following to have your cron job run...

Every Minute:

* * * * * nice /usr/bin/php -f /absolute/path/to/apns.php fetch > /usr/local/apns/apns.log 2>&1 &

Every Five Minutes:

*/5 * * * * nice /usr/bin/php -f /absolute/path/to/apns.php fetch > /usr/local/apns/apns.log 2>&1 &

Every Hour:

0 * * * * nice /usr/bin/php -f /absolute/path/to/apns.php fetch > /usr/local/apns/apns.log 2>&1 &

Every Five Hours:

0 */5 * * * nice /usr/bin/php -f /absolute/path/to/apns.php fetch > /usr/local/apns/apns.log 2>&1 &

STEP 3: Save

Save your new crontab and your cron jobs will now be ready to go :)