PHP code example of cloudlayerio / cloudlayerio-php
1. Go to this page and download the library: Download cloudlayerio/cloudlayerio-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cloudlayerio / cloudlayerio-php example snippets
use CloudLayer\CloudLayer;
$client = new CloudLayer(
apiKey: 'your-api-key',
apiVersion: 'v2',
);
// Convert a URL to PDF
$result = $client->urlToPdf(['url' => 'https://example.com']);
// v2 returns a Job — poll until complete, then download
$job = $client->waitForJob($result->data->id);
$pdfBytes = $client->downloadJobResult($job);
file_put_contents('output.pdf', $pdfBytes);
$client = new CloudLayer(apiKey: 'key', apiVersion: 'v1');
$result = $client->urlToPdf(['url' => 'https://example.com']);
// v1 sync: $result->data is the raw PDF binary
file_put_contents('output.pdf', $result->data);
$client = new CloudLayer(apiKey: 'key', apiVersion: 'v2');
$result = $client->urlToPdf(['url' => 'https://example.com']);
// v2: $result->data is a Job object
$job = $client->waitForJob($result->data->id);
$pdfBytes = $client->downloadJobResult($job);
file_put_contents('output.pdf', $pdfBytes);
$client = new CloudLayer(
apiKey: 'your-api-key', // Required
apiVersion: 'v2', // Required: 'v1' or 'v2'
baseUrl: 'https://api.cloudlayer.io', // Default
timeout: 30000, // Request timeout in ms (default: 30000)
maxRetries: 2, // Retries for data endpoints (default: 2, max: 5)
headers: [], // Additional HTTP headers
);