Upgrade from PHP SDK Legacy to v4.25.0 or Latest Version

Introduction

This is a major application update. Plivo recommends you always use the latest or an active version of our SDKs for guaranteed security, stability, and uptime. The active SDK versions are designed to handle intermittent and regional failures of API requests. In addition, they offer a host of security features, such as protection against DoS attacks and bot detection for suspicious user agents.

Deprecation notice: We’re deprecating Plivo PHP SDK legacy versions lower than 4.25.0 on January 31, 2022. If you use a deprecated version of our SDK after that date, your API requests and voice calls may fail intermittently. Plivo will no longer provide bug fixes to these versions, and our support team may ask you to upgrade before debugging issues.

Migrate your applications

PHP version support

The 4.x version of the Plivo SDK is compatible with PHP versions 7.3 and higher.

Use the command composer require plivo/plivo-php:4.25.0 to upgrade to the active version of the SDK, or composer require plivo/plivo-php to upgrade to the latest version.

After you upgrade to the latest version of the SDK, you should check every program that depends on it and make changes to the syntax for several kinds of operations. Here are examples of how coding differs between the deprecated legacy version of the SDK and the latest active versions.

Import the SDK

Legacy Latest
<?php
require 'vendor/autoload.php';
use Plivo\RestAPI;
   
<?php
require 'vendor/autoload.php';
use Plivo\RestClient;
   

Initialize

Legacy Latest
$p = new RestAPI($auth_id, $auth_token);
   
$client = new RestClient("<auth_id>","<auth_token>");
   

Access resources

Legacy Latest
$response = $p->make_call($params);
   
$response = $client->calls->create($params);
   

Make a call

Legacy Latest
<?php
  require 'vendor/autoload.php';
  use Plivo\RestAPI;
  $auth_id = "<auth_id>";
  $auth_token = "<auth_token>";
  $p = new RestAPI($auth_id, $auth_token);
  $params = array(
      'to' => '2025552323',  
      'from' => '2025551212',
              'answer_url' => "https://s3.amazonaws.com/static.plivo.com/answer.xml",
      'answer_method' => "GET"
  );
  $response = $p->make_call($params);
  print_r ($response);
   
<?php
  require 'vendor/autoload.php';
  use Plivo\RestClient;
  use Plivo\Exceptions\PlivoRestException;
  $client = new RestClient("<auth_id>","<auth_token>");
  try {
      $response = $client->calls->create(
          '+12025551212',
          ['+12025552323'],
          'https://s3.amazonaws.com/static.plivo.com/answer.xml',
      );
      print_r($response);
  }
  catch (PlivoRestException $ex) {
      print_r($ex);
  }
   

Dial XML

Legacy Latest
<?php
    require '../vendor/autoload.php';
    use Plivo\Response;

    $response = new Response();
    
    $params = array(
        'dialMusic' => "https://<yourdomain>.com/dial_music/"
    );
    
    $dial = $response->addDial($params);
    $number = "12025552323";
    $dial->addNumber($number);
    
    Header('Content-type: text/xml');
    echo($response->toXML());
   
<?php
    require '../vendor/autoload.php';
    use Plivo\Response;

    $response = new Response();
    
    $params = array(
        'dialMusic' => "https://<yourdomain>.com/dial_music/"
    );
    
    $dial = $response->addDial($params);
    $number = "12025552323";
    $dial->addNumber($number);
    
    Header('Content-type: text/xml');
    echo($response->toXML());
   

Conference XML

Legacy Latest
<?php
    require '../vendor/autoload.php';
    use Plivo\Response;

    $response = new Response();
    
    $params = array(
        'startConferenceOnEnter' => "false",
        'waitSound' => "https://<yourdomain>.com/waitmusic/"
    );
    
    $conference_name = "My Room";
    $response->addConference($conference_name, $params);
    
    Header('Content-type: text/xml');
    echo($response->toXML());
   
<?php
    require '../vendor/autoload.php';
    use Plivo\Response;

    $response = new Response();
    
    $params = array(
        'startConferenceOnEnter' => "false",
        'waitSound' => "https://<yourdomain>.com/waitmusic/"
    );
    
    $conference_name = "My Room";
    $response->addConference($conference_name, $params);
    
    Header('Content-type: text/xml');
    echo($response->toXML());
   

Record API

Legacy Latest
<?php
    require 'vendor/autoload.php';
    use Plivo\RestAPI;

    $auth_id = "<auth_id>";
    $auth_token = "<auth_token>";
    $p = new RestAPI($auth_id, $auth_token);
    $params = array('call_uuid' => $uuid); 
    $response = $p->record($params);
    print("URL : {$response['response']['url']}");
   
<?php
    require 'vendor/autoload.php';
    use Plivo\RestClient;
    use Plivo\Exceptions\PlivoRestException;
    $client = new RestClient("<auth_id>","<auth_token>");

    try {
        $response = $client->calls->startRecording(
            'eba53b9e-8fbd-45c1-9444-696d2172fbc8'
        );
        print_r($response);
    }
    catch (PlivoRestException $ex) {
        print_r($ex);
    }
   

Record XML

Legacy Latest
<?php
    require '../vendor/autoload.php';
    use Plivo\Response;

    $response = new Response();
    
    $params = array(
        'action' => "https://<yourdomain>.com/get_recording/",
        'startOnDialAnswer' => "true",
        'redirect' => "false"
    );
    
    $response->addRecord($params);
    
    $dial = $response->addDial();
    $number = "2025552323";
    $dial->addNumber($number);
    
    Header('Content-type: text/xml');
    echo($response->toXML());
   
<?php
    require '../vendor/autoload.php';
    use Plivo\Response;

    $response = new Response();
    
    $params = array(
        'action' => "https://<yourdomain>.com/get_recording/",
        'startOnDialAnswer' => "true",
        'redirect' => "false"
    );
    
    $response->addRecord($params);
    
    $dial = $response->addDial();
    $number = "2025552323";
    $dial->addNumber($number);
    
    Header('Content-type: text/xml');
    echo($response->toXML());