PHP Helper

    The Plivo PHP helper simplifies the process of making Plivo API Calls and generating Plivo XML. Please note that this is the legacy version.

    If you are looking for the latest version, you can get it here.

    Prerequisites

    Installation

    Quick Installation

    1. Add plivo/plivo-php as a dependency in your project’s composer.json file:
    1
    2
    3
    4
    5
    
    {
        "require": {
            "plivo/plivo-php": "v1.0.2"
        }
    }
    

    Installing any package via composer would add the dependecies into a sytem generated folder vendor. The path to this folder may vary. Make sure that you include the following line at the begining of your PHP file :

    1
    2
    3
    
    <?php
    
    require 'vendor/autoload.php';
    

    Using the library

    Initializing the RestAPI client

    You can use RestAPI to initialize a REST client that can make API requests to Plivo.

    1
    2
    3
    4
    5
    
    <?php
    
    $auth_id = "Your AUTH_ID";
    $auth_token = "Your AUTH_TOKEN";
    $p = new RestAPI($auth_id, $auth_token);
    

    Send an SMS

    The snippet below shows how you can send an SMS.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    <?php
    
    $params = array(
        'src' => '1111111111',
        'dst' => '2222222222',
        'text' => 'Hello, how are you?'
    );
    
    $response = $p->send_message($params);
    

    Check out Message API documentation for more details.

    Make an Outbound Phone Call

    You can make outbound phone calls to landlines, mobiles, and SIP endpoints (e.g., softphones), in any of our 200+ coverage countries

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    <?php
    
    $params = array(
        'to' => '2222222222',
        'from' => '1111111111',
        'answer_url' => "https://s3.amazonaws.com/static.plivo.com/answer.xml",
        'answer_method' => "GET"
    );
    
    $response = $p->make_call($params);
    

    Check out Call API documentation for more details.

    Examples

    Take a look at the PHP examples on GitHub.

    Reporting Issues

    Please report issues or submit patches using the Github Issue Tracker or Customer Support.

    License

    The Plivo PHP Helper Library is written by the Plivo Team and is distributed under the MIT License.