Not logged in - Login
View History

Library: PHP

We have made a library for PHP to help you start using A Trigger in a minute. This PHP library is made to avoid possible errors in your application. Even if API server become unavailable, your application will work without any problem. On the other hand, all requests are Async by default and no slowness will happen.


  1. First you need to follow Quick Start Guide.
  2. You have this personal details from your Account Setup page:
    1. API Key
    2. API Secret
  3. PHP Sockets enabled server

Step 1: Initialize

First you need to download the PHP Library:

Download PHP Library 0.1.1

Then, add the following to your PHP script:

//require(dirname(__FILE__) . '/ATriggerPHP/ATrigger.php');

You only need to call init once when your php file is requested. All of your files will then have access to the same ATrigger client.

//Debug-friendly: ATrigger::init("YOUR_APIKey","YOUR_APISecret", false, true);

In development you might want to use development settings above to start debugging.

Step 2: Start Using, Functions


//Tags: Tags are required to identify tasks. 
//read more at:
$tags = array();
ATrigger::doCreate("1month", "", $tags);

  1. Required _timeSlice: Xminute, Xhour, Xday, Xmonth, Xyear - more info
  2. Required url: The target url that A Trigger will call it at defined TimeSlice. The library will automatically encode this url. Don't use Server.URLEncode()
  3. Required tags: You need tag your tasks for future identification and to control them using API in the future. read more at tags_* parameters.
  4. [Optional] retries: How many times should try if your server failed(or it was down)? default value: 3
  5. [Optional] count: How many cycles should be repeated? read more at count parameter.
  6. [Optional] first: When should be the first call? You are not required to set time value by default. read more at first parameter.
  7. [Optional] postData: The array for the content you want to HTTP POST to your URL when your task has been triggered.

More advanced example: This code will call your task URL at 1/1/2015. No repeats, no cycles. It will retries 5 times if your server be down.

$tags = array();

$postData = array();

$firstDate = date_create_from_format('d/M/Y:H:i:s', '01/Jan/2015:00:00:01');

ATrigger::doCreate("0minute", "", $tags, $firstDate, 1, 5, $postData);


$tags = array();


Attention: This line will remove the task you've created in the last function(That is tagged "type=test").

  1. Required tags: All tasks with this tags will be removed. read more at tags_* parameters.


$tags = array();


  1. Required tags: All tasks with this tags will be paused. read more at tags_* parameters.


$tags = array();


  1. Required tags: All tasks with this tags will be resumed. read more at tags_* parameters.

Verify Request

All previous functions was for controlling tasks. but verifyRequest will be used to verify URL calls when you want to make sure the request is made from ATrigger servers, using the request IP and verifyRequest function:

//Get real IP of request
function getRealIpAddr()
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    return $ip;

//Check IP
if(ATrigger::verifyRequest(getRealIpAddr())) {
     //Valid request:
     //Do the task here
} else {
     //Invalid request: 
     //The request is not called from ATrigger servers.

  1. Required ip: The request IP that you want to check if it is an IP of ATrigger.


How Pause and Resume works?