PHP SDK

The FastPix PHP SDK provides a powerful, developer-friendly way to integrate video capabilities into your PHP applications. With support for media upload, live streaming, simulcasting, and playback management, you can build any video-based application with ease.



Features

The FastPix PHP SDK provides the following key features:


Media APIs

  • Upload Media: Easily upload media files from URLs or devices to the FastPix platform
  • Manage Media: Perform various media operations such as listing, fetching, updating, and deleting media assets
  • Playback IDs: Create and manage playback IDs to access your media

Live Streaming APIs

  • Create & Manage Live Streams: Stream live events by creating, listing, updating, and deleting live streams
  • Control Stream Access: Generate playback IDs to control who can access your live streams
  • Simulcast: Stream content to multiple platforms simultaneously with ease

Key Benefits

  • Type Safety: Full type hints and strict typing for better development experience
  • Developer-Friendly: Intuitive API design with comprehensive error handling
  • Production Ready: Built for high-performance applications with retry mechanisms
  • Comprehensive Coverage: Complete access to all FastPix platform features

For detailed usage, refer to the FastPix API Reference.


Integration Prerequisite

Before you start using the FastPix PHP SDK, make sure you have the following:

  • PHP (version >= 7.4): This SDK is compatible with PHP version 7.4 or higher on the server side
  • Composer package manager: Required for dependency management
  • FastPix API credentials: You’ll need an Access Token and a Secret Key. You can generate these credentials by following the steps in the Authentication with Access Tokens guide
  • Basic understanding of PHP and REST APIs: Familiarity with PHP development and API integration concepts

Step 1: Installation

The SDK relies on Composer to manage its dependencies.

To install the SDK first add the below to your composer.json file:

{ 
    "repositories": [ 
        { 
            "type": "vcs", 
            "url": "https://github.com/FastPix/fastpix-php.git" 
        } 
    ], 
    "require": { 
        "fastpix/sdk": "*" 
    } 
} 

Then run the following command:

composer update


Step 2: Importing the SDK

Include the autoloader and import the necessary classes in your PHP project:

<?php 
declare(strict_types=1); 
 
require 'vendor/autoload.php'; 
 
use FastPix\Sdk; 
use FastPix\Sdk\Models\Components; 
use FastPix\Sdk\Models\Errors; 


Step 3: Initialization

You can set the security parameters through the security builder method when initializing the SDK client instance. The SDK uses different server URLs for different operations:


For Media Operations

Use the base FastPix server URL:

$sdk = Sdk\FastPix::builder() 
    ->setServerURL('https://v1.fastpix.io') 
    ->setSecurity( 
        new Components\Security( 
            username: 'your-access-token-id', 
            password: 'your-security-key', 
     	 ) 
   	) 
		->build(); 

For Live Stream Operations

Use the live streaming specific server URL:

$sdk = Sdk\FastPix::builder() 
    ->setServerURL('https://v1.fastpix.io/live') 
    ->setSecurity( 
        new Components\Security( 
            username: 'your-access-token-id', 
            password: 'your-security-key', 
        ) 
    ) 
    ->build(); 

Environment Variables (Recommended)

For production applications, use environment variables for security:

$sdk = Sdk\FastPix::builder() 
    ->setServerURL('https://v1.fastpix.io') // or 'https://v1.fastpix.io/live' for live streams 
    ->setSecurity( 
        new Components\Security( 
            username: $_ENV['FASTPIX_ACCESS_TOKEN'], 
            password: $_ENV['FASTPIX_SECRET_KEY'], 
        ) 
    ) 
    ->build(); 


Perform Media Operations


1.1 Create Media from URL

This endpoint allows developers or users to create a new video or audio media in FastPix using a publicly accessible URL. FastPix will fetch the media from the provided URL, process it, and store it on the platform for use.

Use the createMedia() method to create media from a URL. This is useful when you want to import videos from external sources.

For more details refer to Create Media From URL API documentation.

// Initialize SDK for media operations 
$sdk = Sdk\FastPix::builder() 
    ->setServerURL('https://v1.fastpix.io') 
    ->setSecurity( 
        new Components\Security( 
            username: 'your-access-token-id', 
            password: 'your-security-key', 
        ) 
    ) 
    ->build(); 
 
// Create media from URL 
$request = new Components\CreateMediaRequest( 
    input: [ 
        new Components\Input( 
            url: 'https://example.com/video.mp4' 
        ) 
    ] 
); 
 
$response = $sdk->inputVideo->createMedia( 
    request: $request 
); 
 
if ($response->mediaResponseDTO !== null) { 
    echo "Media created successfully!"; 
    echo "Media ID: " . $response->mediaResponseDTO->id; 
    echo "Status: " . $response->mediaResponseDTO->status;

1.2 Upload Media from Device

This endpoint enables you to upload a video file directly from your local device to FastPix for processing and storage. When you invoke this API with your preferred media settings, the response returns an uploadId and a pre-signed URL, providing a streamlined experience for uploading.

Use the directUploadVideoMedia() method to upload media directly from a device or file system.

For more details refer to Upload Media From Device API documentation.

// Upload media directly from device 
$request = new Components\DirectUploadVideoMediaRequest( 
    file: $uploadedFile, // Your uploaded file object 
    metadata: new Components\DirectUploadVideoMediaRequestMetadata( 
        title: 'My Video Title', 
        description: 'Video description' 
    ) 
); 
 
$response = $sdk->inputVideo->directUploadVideoMedia( 
    request: $request 
); 
 
if ($response->mediaResponseDTO !== null) { 
    echo "Media uploaded successfully!"; 
    echo "Media ID: " . $response->mediaResponseDTO->id; 
} 

1.3 List All Media

This endpoint returns a list of all media files created from a URL or uploaded as file objects within your organization. Each media entry contains metadata such as the media ID, creation date, status, and type. It allows you to retrieve a comprehensive overview of your media assets, making it easier to manage and review them.

Use the listMedia() method to retrieve a list of all media files in your account.

For more details refer to List All Media API documentation.

$response = $sdk->manageVideos->listMedia(); 
 
if ($response->mediaListResponseDTO !== null) { 
    foreach ($response->mediaListResponseDTO->data as $media) { 
        echo "Media ID: " . $media->id . "\n"; 
        echo "Title: " . $media->title . "\n"; 
        echo "Status: " . $media->status . "\n"; 
        echo "Duration: " . $media->duration . "\n"; 
    } 
} 

1.4 Get Media by ID

By calling this endpoint, you can retrieve detailed information about a specific media item, including its current status and a playbackId. This is particularly useful for retrieving specific media details when managing large content libraries.

Use the getMedia() method to retrieve details of a specific media file using its media ID.

For more details refer to Get Media by ID API documentation.

$mediaId = 'your-media-id'; 
$response = $sdk->manageVideos->getMedia( 
    mediaId: $mediaId 
); 
 
if ($response->mediaResponseDTO !== null) { 
    $media = $response->mediaResponseDTO; 
    echo "Title: " . $media->title . "\n"; 
    echo "Duration: " . $media->duration . "\n"; 
    echo "Status: " . $media->status . "\n"; 
    echo "Created At: " . $media->createdAt . "\n"; 
} 

1.5 Update Media

This endpoint allows you to update specific parameters of an existing media file. You can modify the key-value pairs of the metadata that were provided in the payload during the creation of media from a URL or when uploading the media as a file object.

Use the updatedMedia() method to update metadata or settings for a specific media file.

For more details refer to Update Media API documentation.

$mediaId = 'your-media-id'; 
$request = new Components\UpdateMediaRequest( 
    title: 'Updated Title', 
    description: 'Updated description' 
); 
 
$response = $sdk->manageVideos->updatedMedia( 
    mediaId: $mediaId, 
    request: $request 
); 
 
if ($response->mediaResponseDTO !== null) { 
    echo "Media updated successfully!"; 
} 

1.6 Delete Media

This endpoint allows you to permanently delete a specific video or audio media file along with all associated data. If you wish to remove a media file from FastPix storage, use this endpoint with the mediaId (either uploadId or id) received during the media’s creation or upload.

Use the deleteMedia() method to remove a media file from your account.

For more details refer to Delete Media API documentation.

$mediaId = 'your-media-id'; 
$response = $sdk->manageVideos->deleteMedia( 
    mediaId: $mediaId 
); 
 
echo "Media deleted successfully!"; 

1.7 Create Media Playback ID

You can create a new playback ID for a specific media asset. If you have already retrieved an existing playbackId using the “Get Media by ID” endpoint for a media asset, you can use this endpoint to generate a new playback ID with a specified access policy.

Use the createMediaPlaybackId() method to generate a playback ID for a media file.

For more details refer to Create Media Playback ID API documentation.

$mediaId = 'your-media-id'; 
$request = new Components\CreateMediaPlaybackIdRequest( 
    accessPolicy: 'public' 
); 
 
$response = $sdk->playback->createMediaPlaybackId( 
    mediaId: $mediaId, 
    request: $request 
); 
 
if ($response->playbackIdResponseDTO !== null) { 
    echo "Playback ID: " . $response->playbackIdResponseDTO->id . "\n"; 
    echo "Playback URL: " . $response->playbackIdResponseDTO->playbackUrl . "\n"; 
} 

1.8 Delete Media Playback ID

This endpoint allows you to remove a specific playback ID associated with a media asset. Deleting a playbackId will revoke access to the media content linked to that ID.

Use the deleteMediaPlaybackId() method to remove a playback ID for a media file.

For more details refer to Delete Media Playback ID API documentation.

$mediaId = 'your-media-id'; 
$playbackId = 'your-playback-id'; 
 
$response = $sdk->playback->deleteMediaPlaybackId( 
    mediaId: $mediaId, 
    playbackId: $playbackId 
); 
 
echo "Playback ID deleted successfully!"; 

Shape


Live Stream Operations


2.1 Create Live Stream

This endpoint allows you to create a new live stream with specified settings. You can configure various parameters such as the stream key, recording settings, and playback options to customize the live streaming experience according to your requirements.

Use the createLiveStream() method to create a new live stream with your desired configuration.

For more details refer to Create Live Stream API documentation.

// Initialize SDK for live stream operations 
$sdk = Sdk\FastPix::builder() 
    ->setServerURL('https://v1.fastpix.io/live') 
    ->setSecurity( 
        new Components\Security( 
            username: 'your-access-token-id', 
            password: 'your-security-key', 
        ) 
    ) 
    ->build(); 
 
// Create a new live stream 
$request = new Components\CreateLiveStreamRequest( 
    name: 'My Live Stream', 
    record: true, 
    simulcast: false 
); 
 
$response = $sdk->startLiveStream->createLiveStream( 
    request: $request 
); 
 
if ($response->liveStreamResponseDTO !== null) { 
    echo "Live stream created successfully!"; 
    echo "Stream ID: " . $response->liveStreamResponseDTO->id; 
    echo "Stream Key: " . $response->liveStreamResponseDTO->streamKey; 
    echo "RTMP URL: " . $response->liveStreamResponseDTO->rtmpUrl; 
} 

2.2 List All Live Streams

This endpoint returns a comprehensive list of all live streams within your organization. It provides detailed information about each stream, including their current status, creation date, and configuration settings, making it easy to manage and monitor your live streaming activities.

Use the listLiveStreams() method to retrieve a list of all live streams in your account.

For more details refer to List All Live Streams API documentation.

$response = $sdk->manageLiveStream->listLiveStreams(); 
 
if ($response->liveStreamListResponseDTO !== null) { 
    foreach ($response->liveStreamListResponseDTO->data as $stream) { 
        echo "Stream ID: " . $stream->id . "\n"; 
        echo "Name: " . $stream->name . "\n"; 
        echo "Status: " . $stream->status . "\n"; 
        echo "Created At: " . $stream->createdAt . "\n"; 
    } 
}

2.3 Get Live Stream by ID

This endpoint allows you to retrieve detailed information about a specific live stream using its unique identifier. It returns comprehensive data including the stream’s current status, configuration settings, and associated metadata, providing you with complete visibility into the stream’s properties and state.

Use the getLiveStream() method to retrieve details of a specific live stream using its stream ID.

For more details refer to Get Live Stream by ID API documentation.

$streamId = 'your-stream-id'; 
$response = $sdk->manageLiveStream->getLiveStream( 
    liveStreamId: $streamId 
); 
 
if ($response->liveStreamResponseDTO !== null) { 
    $stream = $response->liveStreamResponseDTO; 
    echo "Name: " . $stream->name . "\n"; 
    echo "Status: " . $stream->status . "\n"; 
    echo "Stream Key: " . $stream->streamKey . "\n"; 
    echo "RTMP URL: " . $stream->rtmpUrl . "\n"; 
} 

2.4 Update Live Stream

This endpoint enables you to modify the configuration and settings of an existing live stream. You can update various parameters such as the stream name, recording preferences, and other configuration options to adapt the stream to changing requirements or preferences.

Use the updateLiveStream() method to update settings for a specific live stream.

For more details refer to Update Live Stream API documentation.

$streamId = 'your-stream-id'; 
$request = new Components\UpdateLiveStreamRequest( 
    name: 'Updated Stream Name', 
    record: false 
); 
 
$response = $sdk->manageLiveStream->updateLiveStream( 
    liveStreamId: $streamId, 
    request: $request 
); 
 
if ($response->liveStreamResponseDTO !== null) { 
    echo "Live stream updated successfully!"; 
} 

2.5 Delete Live Stream

This endpoint allows you to permanently remove a specific live stream and all its associated data from the FastPix platform. When you delete a live stream, it will be completely removed from your account, including any recordings or metadata associated with it.

Use the deleteLiveStream() method to remove a live stream from your account.

For more details refer to Delete Live Stream API documentation.

$streamId = 'your-stream-id'; 
$response = $sdk->manageLiveStream->deleteLiveStream( 
    liveStreamId: $streamId 
); 
 
echo "Live stream deleted successfully!"; 

2.6 Create Live Stream Playback ID

This endpoint enables you to generate a new playback ID for a specific live stream. The playback ID provides a secure and controlled way to access the live stream content, allowing you to implement custom access policies and restrictions for your live streaming content.

Use the createLiveStreamPlaybackId() method to generate a playback ID for a live stream.

For more details refer to Create Live Stream Playback ID API documentation.

$streamId = 'your-stream-id'; 
$request = new Components\CreateLiveStreamPlaybackIdRequest( 
    accessPolicy: 'public' 
); 
 
$response = $sdk->playback->createLiveStreamPlaybackId( 
    liveStreamId: $streamId, 
    request: $request 
); 
 
if ($response->playbackIdResponseDTO !== null) { 
    echo "Playback ID: " . $response->playbackIdResponseDTO->id . "\n"; 
    echo "Playback URL: " . $response->playbackIdResponseDTO->playbackUrl . "\n"; 
} 

2.7 Delete Live Stream Playback ID

This endpoint allows you to remove a specific playback ID associated with a live stream. Deleting a playback ID will revoke access to the live stream content linked to that ID, providing you with control over who can access your live streaming content.

Use the deleteLiveStreamPlaybackId() method to remove a playback ID for a live stream.

For more details refer to Delete Live Stream Playback ID API documentation.

$streamId = 'your-stream-id'; 
$playbackId = 'your-playback-id'; 
 
$response = $sdk->playback->deleteLiveStreamPlaybackId( 
    liveStreamId: $streamId, 
    playbackId: $playbackId 
); 
 
echo "Live stream playback ID deleted successfully!"; 

2.8 Get Live Stream Playback ID

Retrieves details about a previously created playback ID. If you provide the distinct playback ID that was given back to you in the previous stream or playbackId create request, FastPix will provide the relevant playback details such as the access policy.

Use the getLiveStreamPlaybackId() method to retrieve the playback policy for a specific live stream playback ID.

For more details refer to Get Live Stream Playback ID API documentation.

$mediaType = 'livestream'; 
$streamId = 'your-stream-id'; 
$playbackId = 'your-playback-id'; 
 
$response = $sdk->playback->getLiveStreamPlaybackId( 
    mediaType: $mediaType, 
    streamId: $streamId, 
    playbackId: $playbackId 
); 
 
if ($response->playbackIdResponseDTO !== null) { 
    echo "Playback Policy: " . $response->playbackIdResponseDTO->accessPolicy . "\n"; 
} 

2.9 Create Simulcast

Lets you to create a simulcast for a parent live stream. A simulcast enables you to broadcast the live stream to multiple platforms simultaneously (e.g., YouTube, Facebook, or Twitch). This feature is useful for expanding your audience reach across different platforms. However, a simulcast can only be created when the parent live stream is in an idle state (i.e., not currently live or disabled). Additionally, only one simulcast target can be created per API call.

Use the createSimulcastOfStream() method to create a new simulcast for a live stream.

For more details refer to Create Simulcast API documentation.

$streamId = 'your-stream-id'; 
$request = new Components\CreateSimulcastRequest( 
    url: 'rtmps://live.fastpix.io:443/live', 
    streamKey: 'your-stream-key', 
    metadata: [ 
        'platform' => 'youtube', 
        'channel' => 'my-channel' 
    ] 
); 
 
$response = $sdk->simulcastStream->createSimulcastOfStream( 
    streamId: $streamId, 
    request: $request 
); 
 
if ($response->simulcastResponseDTO !== null) { 
    echo "Simulcast created successfully!"; 
    echo "Simulcast ID: " . $response->simulcastResponseDTO->id; 
} 

2.10 Get Simulcast Details

Retrieves the details of a specific simulcast associated with a parent live stream. By providing both the streamId of the parent stream and the simulcastId, FastPix returns detailed information about the simulcast, such as the stream URL, the status of the simulcast (active or idle), and metadata.

Use the getSpecificSimulcastOfStream() method to retrieve details of a specific simulcast for a live stream.

For more details refer to Get Simulcast Details API documentation.

$streamId = 'your-stream-id'; 
$simulcastId = 'your-simulcast-id'; 
 
$response = $sdk->simulcastStream->getSpecificSimulcastOfStream( 
    streamId: $streamId, 
    simulcastId: $simulcastId 
); 
 
if ($response->simulcastResponseDTO !== null) { 
    $simulcast = $response->simulcastResponseDTO; 
    echo "Simulcast ID: " . $simulcast->id . "\n"; 
    echo "URL: " . $simulcast->url . "\n"; 
    echo "Is Enabled: " . ($simulcast->isEnabled ? 'Yes' : 'No') . "\n"; 
} 

2.11 Update Simulcast

Allows you to enable or disable a specific simulcast associated with a parent live stream. The status of the simulcast can be updated at any point, whether the live stream is active or idle. However, once the live stream is disabled, the simulcast can no longer be modified.

Use the updateSpecificSimulcastOfStream() method to modify the configuration of a simulcast stream.

For more details refer to Update Simulcast API documentation.

$streamId = 'your-stream-id'; 
$simulcastId = 'your-simulcast-id'; 
$request = new Components\UpdateSimulcastRequest( 
    isEnabled: false, 
    metadata: [ 
        'status' => 'paused' 
    ] 
); 
 
$response = $sdk->simulcastStream->updateSpecificSimulcastOfStream( 
    streamId: $streamId, 
    simulcastId: $simulcastId, 
    request: $request 
); 
 
if ($response->simulcastResponseDTO !== null) { 
    echo "Simulcast updated successfully!"; 
} 

2.12 Delete Simulcast

Allows you to delete a simulcast using its unique simulcastId, which was returned during the simulcast creation process. Deleting a simulcast stops the broadcast to the associated platform, but the parent stream will continue to run if it is live. This action is irreversible, and a new simulcast would need to be created if you want to resume streaming to the same platform.

Use the deleteSimulcastOfStream() method to remove a specific simulcast from a live stream.

For more details refer to Delete Simulcast API documentation.

$streamId = 'your-stream-id'; 
$simulcastId = 'your-simulcast-id'; 
 
$response = $sdk->simulcastStream->deleteSimulcastOfStream( 
    streamId: $streamId, 
    simulcastId: $simulcastId 
); 
 
echo "Simulcast deleted successfully!"; 


Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default an API error will raise a Errors\APIException exception, which has the following properties:

PropertyTypeDescription
$messagestringThe error message
$statusCodeintThe HTTP status code
$rawResponse*?The raw HTTP response
$bodystringThe response content

Example Error Handling

try { 
    $response = $sdk->startLiveStream->createNewStream($request); 
     
    if ($response->liveStreamResponseDTO !== null) { 
        // Handle success 
        echo "Stream created: " . $response->liveStreamResponseDTO->id; 
    } 
} catch (Errors\UnauthorizedException $e) { 
    // Handle authentication errors 
    error_log("Authentication failed: " . $e->getMessage()); 
} catch (Errors\ValidationErrorResponse $e) { 
    // Handle validation errors 
    error_log("Validation error: " . $e->getMessage()); 
} catch (Errors\APIException $e) { 
    // Handle general API errors 
    error_log("API error: " . $e->getMessage()); 
} 


Support & Resources

Getting Help

  • Documentation: Visit the FastPix API Reference for detailed API documentation
  • GitHub Issues: Report bugs or request features on the GitHub repository
  • Community: Join the FastPix developer community for discussions and support

Additional Resources

  • SDK Repository:
  • API Documentation:
  • FastPix Platform:

SDK Maturity

This SDK is currently in beta. While it’s production-ready, there may be breaking changes between versions without a major version update. We recommend:

  • Pin to specific versions for production applications
  • Test thoroughly before deploying updates
  • Monitor the changelog for any breaking changes