Sending Data with Cron
Because the default mode of Kissmetrics sends a request to our tracking servers every time you record data, any slow connection between our servers and your servers could result in your site being adversely affected. Therefore we have a provided a mode that runs in the background via cron. You might also consider looking at our 3rd-party APIs.
Usage
The cron mode writes all requests to a log for later processing instead . It does require a little more set up on your end, but protects your site in the unlikely event that the Kissmetrics tracking servers are down, unreachable or slow to respond. To use this mode first call init with the appropriate args. Here is an example using the Ruby Library:
Ruby
PHP
Enabling the Cron Job
As logs will not automatically be uploaded to Kissmetrics, it needs to be handled by some external service. A suitable method may be a simple cronjob. The crontab line below shows a cronjob which will upload all the events every five minutes. It is OK to have multiple processes uploading files at the same time. The Ruby Library and PHP Library takes care of not uploading duplicate data.
Note: We are passing in the same log_dir
that we set above.
Ruby
*/5 * * * * /usr/bin/ruby /km-install-dir/bin/km_send
PHP
*/5 * * * * /usr/bin/php /km-install-dir/km.php "your key" /var/logs/km