Cron Job
    • 1 Minute to read
    • Dark
      Light

    Cron Job

    • Dark
      Light

    Article summary

    We recommend using a cron job to send logfile requests to the Mapp tracking server every few minutes and empty your file to keep it at a manageable size. You have two options:

    Custom Cron Job File

    This option requires you to write your own cron job file and use our MappIntelligenceCronjob class.

    Methods

    constructor

    For a complete configuration of the Mapp Intelligence Cronjob please check Configuration.

    /**
     * @param array $config Mapp Intelligence config
     * @throws MappIntelligenceException Mapp Intelligence configuration exception
     */
    $mappIntelligenceCronjob = new MappIntelligenceCronjob($config);

    run

    Send the logfile requests to the Mapp tracking server and delete your logfiles to keep it at a mangeable size. Returns the following results:

    • 0: All data was sent successfully.

    • 1: An error has occurred.

    /**
     * @return int Status
     */
    $mappIntelligenceCronjob->run();
    Example
    require_once __DIR__ . '/lib/MappIntelligenceCronjob.php'
    
    $status = 1;
    try {
    	$mappIntelligenceConfig = new MappIntelligenceConfig();
    	$mappIntelligenceConfig.setTrackId("111111111111111");
    	$mappIntelligenceConfig.setTrackDomain("analytics01.wt-eu02.net");
    	$mappIntelligenceConfig.setConsumerType(MappIntelligenceConsumerType::FILE_ROTATION);
    	$mappIntelligenceConfig.setFilePath("/path/to/your/log/file/");
    	$mappIntelligenceConfig.setFilePrefix("MappIntelligenceData");
    
        $cronjob = new MappIntelligenceCronjob($mappIntelligenceConfig);
     
        $status = $cronjob->run();
    } catch (Exception $e) {}
     
    exit($status)
    

    Predefined Cron Job Script

    This option allows you to use our predefined cronjob.php script, which is included in our repository

    Short notation

    Long notation

    Description

    -i

    --trackId

    Enter your Mapp Intelligence track ID provided by Mapp.

    -d

    --trackDomain

    Enter your Mapp Intelligence tracking URL.

    -t

    --consumerType

    Enter your current file consumer type. Options: "FILE", "FILE_ROTATION". Defaults to "FILE".

    -c

    --config

    Enter the path to your configuration file (*.ini).


    -f

    --filename

    Enter the path to your request logging file. Only relevant for file consumer type "FILE". Defaults to "/tmp/MappIntelligenceRequests.log".

    -f

    --filePath

    Enter the path to your request logging files. Only relevant for file consumer type "FILE_ROTATION". Defaults to "/tmp/".

    -p

    --filePrefix

    Enter the prefix for your request logging files. Only relevant for file consumer type "FILE_ROTATION". Defaults to "MappIntelligenceRequests".



    --deactivate

    Deactivate the tracking functionality.


    --debug

    Activates the debug mode. The debug mode sends messages to the command line.


    --help

    Display the help and exit.


    --version

    Display version and exit.

    Example
    $ php cronjob.php -i 111111111111111 -d analytics01.wt-eu02.net -t FILE_ROTATION -f /tmp/ -p MappIntelligenceData
     
    $ php cronjob.php -i 111111111111111 -d analytics01.wt-eu02.net -t FILE_ROTATION -f /tmp/ -p MappIntelligenceData --debug
     
     
    $ php cronjob.php -c /path/to/your/configuration/file/config.ini
     
    $ php cronjob.php -c /path/to/your/configuration/file/config.ini --debug

    Define a Cron Job

    To create your crontab file, type the following command at the shell prompt crontab -e and add the following lines:

    # sends every five minutes the tracking data to the Mapp tracking serve
    */5 * * * * php ./cronjob.php -c /path/to/your/configuration/file/config.ini


    Was this article helpful?

    What's Next