Setting up and testing the Urban Airship PHP Library

The Urban Airship PHP Library is dependent on three other php libraries: Composer, Httpful, and Monolog.

Install all dependancies for Mac OS X

  1. Open the Terminal, and from your php project folder, install Composer:
    $ curl -sS https://getcomposer.org/installer | php
  2. Now run Composer. This will install the remaining dependancies:
    $ php composer.phar install

Create and run the test script

  1. Create a php script to test the Urban Airship PHP library using the code below. Name it test.php.
    <?php
    
    require_once 'vendor/autoload.php';
    use UrbanAirship\Airship; use UrbanAirship\AirshipException; use UrbanAirship\UALog; use UrbanAirship\Push as P; use Monolog\Logger; use Monolog\Handler\StreamHandler;
    UALog::setLogHandlers(array(new StreamHandler("php://stdout", Logger::DEBUG)));
    $airship = new Airship("<app key>", "<master secret>");
    try {     $response = $airship->push()         ->setAudience(P\all)         ->setNotification(P\notification("Hello from php"))         ->setDeviceTypes(P\all)         ->send(); } catch (AirshipException $e) {     print_r($e); }
  2. Replace the <app key> and <master secret> in line 14 with the app key and master secret from your Urban Airship app. This is available on the Settings > APIs & Integrations page of your app on the Urban Airship Go Dashboard.
  3. Now test the script:
    $ php test.php
    You should receive a success response from the API.

Related Content: