• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

PHP API

Updating Device Data

Keeping device data up-to-date is almost as important as regularly installing security updates as it affects your customers. Correctly identifying the latest devices, Operating Systems and browsers allows you to provide your customers with the most relevant version of your website and content. On average our data team finds and adds over 200 new devices to our database each week.

We understand that manually downloading the latest data file is time consuming and inefficient, so we have introduced automatic updates functionality. This allows your API to automatically retrieve the latest data file from our servers using your licence key and update your current device data file with the latest version.

If you are a Premium or Enterprise customer you can get started with automatic data updates straight away, see the next section for more details. Lite data users are welcome to test drive automatic updates by signing up with our free evaluation programme. When trialling the Premium and Enterprise data file versions you can experience the  benefits of having more properties and device combinations as well as more frequent updates. Compare the features offered by each data file.

For general information about the auto update feature see the Automatic Data Updates documentation page.

PHP Specific Information

The PHP common API now supports automatic updates which running an On-Premise installation. Automatic updates is realised by calling the ‘update.php’ script found in the common API directory. To enable automatic updates, you will need to set up a scheduled job:

Linux

It is important that the data file has the correct permissions to be accessed by the webserver, this can be done by setting the owning user/group to that of the webserver or updating the ‘rwx’ permissions on the datafile. E.g. ‘chmod 755 /var/www/html/51Degrees-EnterpriseV3.2.dat

  1. - Create a bash script called ‘51DUpdate.sh’ with the contents: content=$(curl -L localhost/update.php)
  2. - Save this in /etc/cron.daily/
  3. - Run crontab -e
  4. - Append the following line to enable automatic updates: 0 0 * * * /etc/cron.daily/51DUpdate.sh

The cron job will now execute every day at midnight, the script will make a request to the ‘update.php’ script. The script will download and update the existing data file then reload the provider.

To prevent users from forcing an update it is recommended that access to the ‘update.php’ file is denied from external interfaces.

Windows

On windows, automatic updates can be enabled using a PowerShell script that is run via scheduled task. To set up automatic updates on Windows, make a PowerShell script called 51DUpdate.ps1 with the contents:

$content = Invoke-WebRequest http://localhost/

A Scheduled Task can be used to run this script with a frequency of once a day. As the most frequently updated data file is released daily, there is little to no benefit to running this more than once per day.