Download the PHP package twilio/sdk without Composer
On this page you can find all versions of the php package twilio/sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package sdk
Short Description A PHP wrapper for Twilio's API
License MIT
Homepage https://github.com/twilio/twilio-php
Informations about the package sdk
twilio-php
Documentation
The documentation for the Twilio API can be found here.
The PHP library documentation can be found here.
Versions
twilio-php
uses a modified version of Semantic Versioning for all changes. See this document for details.
Supported PHP Versions
This library supports the following PHP implementations:
- PHP 7.2
- PHP 7.3
- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
Installation
You can install twilio-php
via composer or by downloading the source.
Via Composer
twilio-php
is available on Packagist as the twilio/sdk
package:
Test your installation
Here is an example of using the SDK to send a text message:
Without Composer
While we recommend using a package manager to track the dependencies in your application, it is possible to download and use the PHP SDK manually. You can download the full source of the PHP SDK from GitHub, and browse the repo if you would like. To use the SDK in your application, unzip the SDK download file in the same directory as your PHP code. In your code, you can then require the autoload file bundled with the SDK.
Usage
Make a Call
Warning It's okay to hardcode your credentials when testing locally, but you should use environment variables to keep them secret before committing any code or deploying to production. Check out How to Set Environment Variables for more information.
Get an existing Call
Iterate through records
The library automatically handles paging for you. Collections, such as calls
and messages
, have read
and stream
methods that page under the hood. With both read
and stream
, you can specify the number of records you want to receive (limit
) and the maximum size you want each page fetch to be (pageSize
). The library will then handle the task for you.
read
eagerly fetches all records and returns them as a list, whereas stream
returns an iterator and lazily retrieves pages of records as you iterate over the collection. You can also page manually using the page
method.
For more information about these methods, view the auto-generated library docs.
Use the read
method
Specify Region and/or Edge
To take advantage of Twilio's Global Infrastructure, specify the target Region and/or Edge for the client:
A Client
constructor without these parameters will also look for TWILIO_REGION
and TWILIO_EDGE
variables inside the current environment.
This will result in the hostname
transforming from api.twilio.com
to api.sydney.au1.twilio.com
.
Enable Debug Logging
There are two ways to enable debug logging in the default HTTP client. You can create an environment variable called TWILIO_LOG_LEVEL
and set it to debug
or you can set the log level to debug:
Generate TwiML
To control phone calls, your application needs to output TwiML.
Use Twilio\TwiML\(Voice|Messaging|Fax)Response
to easily chain said responses.
That will output XML that looks like this:
Handle exceptions
When something goes wrong during client initialization, in an API request, or when creating TwiML, twilio-php will throw an appropriate exception. You should handle these exceptions to keep your application running and avoid unnecessary crashes.
The Twilio client
For example, it is possible to get an authentication exception when initiating your client, perhaps with the wrong credentials. This can be handled like so:
CurlClient
When initializing the curl client, you will see an EnvironmentException if curl is not installed on your system.
TwilioException
TwilioException
can be used to handle API errors, as shown below. This is the most common exception type that you will most likely use.
TwimlException
When building TwiML with twilio-php
, if the result does not conform to what the API expects, you will see a TwimlException
which you then need to handle like so:
Debug API requests
To assist with debugging, the library allows you to access the underlying request and response objects. This capability is built into the default Curl client that ships with the library.
For example, you can retrieve the status code of the last response like so:
Use a custom HTTP Client
To use a custom HTTP client with this helper library, please see the advanced example of how to do so.
Docker image
The Dockerfile
present in this repository and its respective twilio/twilio-php
Docker image are currently used by Twilio for testing purposes only.
Getting help
If you need help installing or using the library, please check the Twilio Support Help Center first, and file a support ticket if you don't find an answer to your question.
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!