PHP code example of marceloeatworld / runpod-serverless-php
1. Go to this page and download the library: Download marceloeatworld/runpod-serverless-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/ */
marceloeatworld / runpod-serverless-php example snippets
use MarceloEatWorld\RunPod\RunPod;
$runpod = new RunPod('your-api-key');
$endpoint = $runpod->endpoint('your-endpoint-id');
// Async run
$result = $endpoint->run([
'prompt' => 'A beautiful landscape'
]);
// Check status
if ($result->isInQueue()) {
echo "Job queued with ID: " . $result->id;
}
// Get status later
$status = $endpoint->status($result->id);
if ($status->isCompleted()) {
$output = $status->getOutput();
echo "Job completed!";
} elseif ($status->isFailed()) {
$error = $status->getError();
echo "Job failed: " . $error;
}
// Status checks
$response->isCompleted(); // true if status is COMPLETED
$response->isInQueue(); // true if status is IN_QUEUE
$response->isInProgress(); // true if status is IN_PROGRESS
$response->isFailed(); // true if status is FAILED
$response->isCancelled(); // true if status is CANCELLED
// Data access
$response->id; // Job ID
$response->status; // Status string
$response->data; // Complete response data
// Helper methods
$response->getOutput(); // Get job output data
$response->getError(); // Get error details
$response->getMetrics(); // Get execution metrics
$response->getExecutionTime(); // Get execution time in ms
$response->getDelayTime(); // Get delay time in ms