1. Go to this page and download the library: Download ldkafka/yii2-google-gemini 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/ */
$gemini->cacheType = 'client';
$gemini->cacheTtl = 3600;
// First message
$resp = $gemini->chat('gemini-2.5-flash', 'My name is Alice', 'user123');
// Follow-up (remembers context)
$resp = $gemini->chat('gemini-2.5-flash', 'What is my name?', 'user123');
// Response: "Your name is Alice."
$gemini->cacheType = 'server';
// Create cache with system instruction (sistant-id',
'You are a helpful travel assistant. [... long system instruction ...]',
3600
);
// Use cached context
$resp = $gemini->chatServer('gemini-2.5-flash', 'Best beaches in Sydney?', 'assistant-id');
$gemini->systemInstruction = [
'parts' => [['text' => 'You are a helpful coding assistant who explains concepts simply.']]
];
$resp = $gemini->generateContent('gemini-2.5-flash', 'Explain recursion');
// Upload a large video file
$resp = $gemini->uploadFile('/path/to/video.mp4', 'My Video', 'video/mp4');
$fileUri = $resp['data']['file']['uri'];
// Use in generation
$content = [[
'parts' => [
['text' => 'Summarize this video'],
['file_data' => [
'file_uri' => $fileUri,
'mime_type' => 'video/mp4'
]]
]
]];
$resp = $gemini->generateContent('gemini-2.5-flash', $content);
// List uploaded files
$files = $gemini->listFiles();
// Delete file
$gemini->deleteFile('files/abc123');
$tokens = $gemini->countTokens('gemini-2.5-flash', 'Your prompt text here');
echo "This prompt will use approximately $tokens tokens\n";
// List all available models
$models = $gemini->listModels();
foreach ($models['data']['models'] as $model) {
echo "{$model['name']}: {$model['displayName']}\n";
}
// Get specific model details
$model = $gemini->getModel('gemini-2.5-flash');
echo "Context window: {$model['data']['inputTokenLimit']} tokens\n";