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 ATrigger.com 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.
- First you need to follow Quick Start Guide.
- You have this personal details from your Account Setup page:
- API Key
- API Secret
- PHP Sockets enabled server
Step 1: InitializeFirst you need to download the PHP Library:
Then, add the following to your PHP script:
require_once("/path/to/atriggerphp/ATrigger.php"); //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.
ATrigger::init("YOUR_APIKey","YOUR_APISecret"); //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: http://atrigger.com/docs/wiki/9/rest-api-v10-parameter-tag_ $tags = array(); $tags['type']='test'; //Create ATrigger::doCreate("1month", "http://www.example.com/myTask?something", $tags);
_timeSlice: Xminute, Xhour, Xday, Xmonth, Xyear - more info
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()
tags: You need tag your tasks for future identification and to control them using API in the future. read more at tags_* parameters.
retries: How many times should try if your server failed(or it was down)? default value: 3
count: How many cycles should be repeated? read more at count parameter.
first: When should be the first call? You are not required to set time value by default. read more at first parameter.
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(); $tags['type']='test'; $postData = array(); $postData['type']='test'; $firstDate = date_create_from_format('d/M/Y:H:i:s', '01/Jan/2015:00:00:01'); ATrigger::doCreate("0minute", "http://www.example.com/myTask?something", $tags, $firstDate, 1, 5, $postData);
//Tags: $tags = array(); $tags['type']='test'; //Delete ATrigger::doDelete($tags);
Attention: This line will remove the task you've created in the last function(That is tagged "type=test").
tags: All tasks with this tags will be removed. read more at tags_* parameters.
//Tags: $tags = array(); $tags['type']='test'; //Pause ATrigger::doPause($tags);
tags: All tasks with this tags will be paused. read more at tags_* parameters.
//Tags: $tags = array(); $tags['type']='test'; //Resume ATrigger::doResume($tags);
tags: All tasks with this tags will be resumed. read more at tags_* parameters.